相关疑难解决方法(0)

在运行时删除顶级容器

不幸的是,看起来这个最近封闭的问题还不太清楚.这是典型的输出:

run:
    Trying to Remove JDialog
    Remove Cycle Done :-)
    Checking if still exists any of TopLayoutContainers
JFrame
JDialog
    Will Try Remove Dialog again, CycleNo. 1
 -----------------------------------------------------------
    Trying to Remove JDialog
    Remove Cycle Done :-)
    Checking if still exists any of TopLayoutContainers
JFrame
JDialog
    Will Try Remove Dialog again, CycleNo. 2
 -----------------------------------------------------------
    Trying to Remove JDialog
    Remove Cycle Done :-)
    Checking if still exists any of TopLayoutContainers
JFrame
JDialog
    Will Try Remove Dialog again, CycleNo. 3
 -----------------------------------------------------------
    Trying …
Run Code Online (Sandbox Code Playgroud)

java swing runtime jdialog

18
推荐指数
4
解决办法
9582
查看次数

在java/swing中关闭窗口时采取的正确行动是什么?

我刚在CustomUIPanel类中编写了这个测试代码:

public static void main(String[] args) {
    final JDialog dialog = CustomUIPanel.createDialog(null, 
       CustomUIPanel.selectFile());
    dialog.addWindowListener(new WindowAdapter() {
        @Override public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

它是正确的,如果CustomUIPanel.main()是程序的入口点,但它让我想知道:如果另一个类要求CustomUIPanel.main()测试怎么办?然后我的电话System.exit(0)是不正确的.

如果没有顶级窗口,有没有办法告诉Swing事件调度线程自动退出?

如果不是,如果目标是让所有顶级窗口关闭时程序退出,那么JDialog/JFrame在关闭时做什么是正确的?

java swing dialog

14
推荐指数
1
解决办法
1万
查看次数

基本Java Swing,如何退出和处理您的应用程序/ JFrame

使用这样的代码处理JFrame的好方法是什么?我想处理Window出口和窗口关闭.

我知道我们不应该使用System.exit();

public class JavaCellularAutomataSquare {

  public static final String TITLE = "Cellular Automata - Squaring Example";

  private int maxWidth = 600;
  private int maxHeight = 600;

  public void launch() {    
    final JFrame frame = new JFrame(TITLE);   
    frame.setLocation(20, 20);    
    frame.setPreferredSize(new Dimension(maxWidth, maxHeight));
    frame.setResizable(false);
    frame.setFocusable(true);

    final JPanel panel = new JPanel();
    panel.setLocation(20, 20);
    panel.setVisible(true);
    panel.setPreferredSize(new Dimension(maxWidth, maxHeight));    
    panel.setFocusable(true);
    panel.setBackground(Color.white);

    // Panel setup, toggle visibility on frame
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);    
  }

}
Run Code Online (Sandbox Code Playgroud)

java swing windowlistener

10
推荐指数
2
解决办法
3万
查看次数

标签 统计

java ×3

swing ×3

dialog ×1

jdialog ×1

runtime ×1

windowlistener ×1