当前位置: 代码迷 >> J2SE >> 通过一个按钮响应添加另一个组件,需要放大或者拉动窗口组件在会出现?解决办法
  详细解决方案

通过一个按钮响应添加另一个组件,需要放大或者拉动窗口组件在会出现?解决办法

热度:5598   发布时间:2013-02-25 00:00:00.0
通过一个按钮响应添加另一个组件,,需要放大或者拉动窗口组件在会出现??
public class ButtonAddPanel extends JFrame implements ActionListener{
/**
* @param args
*/
JButton jb;
public static void main(String[] args) {
// TODO Auto-generated method stub
new ButtonAddPanel();
}
public ButtonAddPanel(){
jb = new JButton("aa");
jb.addActionListener(this);
this.add(jb,"North");
this.setSize(200,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
if(arg0.getSource() == jb){
this.add(new MyPanel(),"South");
}
}
class MyPanel extends JPanel{
JTextArea jt;
public MyPanel(){
jt = new JTextArea("aaaaaaaaaaaaaaaaaaaaa");
this.add(jt);
this.setVisible(true); 
}
}
}
求解,为什么通过一个按钮响应添加另一个组件,,需要放大或者拉动窗口组件在会出现??

------解决方案--------------------------------------------------------
很明显,你添加了组件后没有刷新屏幕。 也就是所谓的额 update..()
------解决方案--------------------------------------------------------
很明显,你添加了组件后没有刷新屏幕。 也就是所谓的额 update..()
  相关解决方案