jDialog显示的问题,大家看看呀 jDialog显示用的是setVisible(true);关闭的时候用meg1.setVisible(false);,但是当第二次再找开这个jdialog的时候,只有个框框,里面的组件没有显示出来,或显示不完全,这是怎么回事呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 检查你的代码,我这里没问题import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;public class Test extends JFrame { private JDialog dia = null; private JButton button = null, b = null; public Test() { dia = new JDialog(this, true); b = new JButton("Close"); dia.getContentPane().add(b); dia.setSize(200, 100); b.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { dia.setVisible(false); }}); button = new JButton("Show Dialog"); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { dia.setVisible(true); }}); this.getContentPane().add(button); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(300, 200); this.setVisible(true); } public static void main(String[] args) { new Test(); }} 谢谢,我的问题应该是初始化的进候出错了,我在弹出框里加载了JTree,JTree 的初始始化过程是在构造方法里完成的。这样就出错。 后来,我把树的初始化过程放在按钮触发的过程中,就没问题了,不知是怎么回事。我这样说大家能明白吗? 使用 setVisiable 应当不会出现你的问题。第二次应当不会再初始化。尝试一下:JComponent.revalidate重新布局一次。 用eclipse写的java小应用程序没main函数打包成jar文件途中遇到问题 有个需求不知道怎么写效率高点!关于按需对数组排序。不知道怎么做效率高点啊? jar 文件解压报错 高手请进,如何让Jboss 3.2.x 中的session bean中多个线程中共享一个jta事务? 顺序读完一个文件后如何跳回文件开头 用DatagramSocket发UDP的问题 帮我看看这个小程序是什么问题 急!如何利用poi在excel中动态的插入图片(如.jpg),答了就给分。 中国软件向印度学什么 (zt)-----唉!不服人家不行! java 请教一个启动界面??? 对象 和 实例 有什么区别?
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;public class Test extends JFrame {
private JDialog dia = null;
private JButton button = null, b = null;
public Test() {
dia = new JDialog(this, true);
b = new JButton("Close");
dia.getContentPane().add(b);
dia.setSize(200, 100);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
dia.setVisible(false);
}});
button = new JButton("Show Dialog");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
dia.setVisible(true);
}});
this.getContentPane().add(button);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300, 200);
this.setVisible(true);
} public static void main(String[] args) {
new Test();
}
}
后来,我把树的初始化过程放在按钮触发的过程中,就没问题了,不知是怎么回事。我这样说大家能明白吗?
第二次应当不会再初始化。
尝试一下:JComponent.revalidate
重新布局一次。