这样试试看行不行.从这开始test.setLayout(bl);用这些替换一下
Container c=test.getContentPanel();
c.setLayout(bl);
c.add(new Button("North"),BorderLayout.NORTH);
c.add(new Button("South"),BorderLayout.SOUTH);
c.add(new Button("West"),BorderLayout.WEST);
c.add(new Button("East"),BorderLayout.EAST);
Container c=test.getContentPanel();
c.setLayout(bl);
c.add(new Button("North"),BorderLayout.NORTH);
c.add(new Button("South"),BorderLayout.SOUTH);
c.add(new Button("West"),BorderLayout.WEST);
c.add(new Button("East"),BorderLayout.EAST);
test.setLocation(100,100);
Button button=new Button("This is a Button");
button.setVisible(true);
BorderLayout bl=new BorderLayout(0,5);
test.setLayout(bl);
test.add(new Button("North"),BorderLayout.NORTH);
test.add(new Button("South"),BorderLayout.SOUTH);
test.add(new Button("West"),BorderLayout.WEST);
test.add(new Button("East"),BorderLayout.EAST);
test.setSize(300,300);
test.setVisible(true);
Dialog dlg=new Dialog(test,"attion",true);
dlg.setSize(240,150);
//dlg.show();
这一句代码一定要有!
test.setVisible(true);这句放到你添加Button完之后就可以了,而且一般都应该这样:
在做完所有的添加后才显示!
///////////////////////////////
说来我发现这样解决的过程有些搞笑,我测试了你的代码,偶然点了最大化按钮,发现你的Button显示出来了,在还原还是有。而点最小化在还原却还是没有,这很奇怪,看来他们的处理是不一样了。后来想想虽然解决了你的问题,可是更深我还没有搞清楚,有知道的吗,出招吧。
另外你的frame 不能关闭,我在main ()中加了如下的语句,能够关闭你的frame
test.addWindowListener(new WindowAdapter(){public void windowClosing (WindowEvent e){
System.exit(0);
}
});
public void pack()
Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated.
show
public void show()
Makes the Window visible. If the Window and/or its owner are not yet displayable, both are made displayable. The Window will be validated prior to being made visible. If the Window is already visible, this will bring the Window to the front.多谢 hehecafe给我提出错误.