import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;public class AtributeEditPerform extends JFrame {
/**
 * 
 */
private static final long serialVersionUID = 1L;
static JButton addButton = new JButton("增加");
static JButton DeleteButton = new JButton("删除");
static JButton closeButton = new JButton("取消"); public static void main(String[] args) {
new AtributeEditPerform();
} protected void initPanel() {
// 添加化组件
addComment();
} private void addComment() {
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
panel.add(addButton);
panel.add(DeleteButton);
panel.add(closeButton);
this.setLayout(new BorderLayout());
this.add(panel, BorderLayout.SOUTH);

} // 构造函数设置窗体显示位置属性,初始化
public AtributeEditPerform() {
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
setSize(screenWidth / 3, screenHeight / 3);
setLocation(screenWidth / 3, screenHeight / 3);
this.setVisible(true);
this.setTitle("属性修改");
this.setResizable(false);
addComment();
}
}红色部分是按钮的初始化,但是窗体运行起来之后BUTTON显示不了,求高手解决PS:JDK版本是1.4

解决方案 »

  1.   

    一般是做好所有的初始化操作再显示整个容器,将addComment();放到this.setVisible(true);之前。
      

  2.   

    this.add(panel, BorderLayout.SOUTH);===>
    this.getContextPane().add(panel,BorderLayout.SOUTH);
      

  3.   

     this.setLayout(new BorderLayout());
      this.add(panel, BorderLayout.SOUTH);===> 
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(panel,BorderLayout.SOUTH);