首页 > 解决方案 > 在 actionperformed 中创建 JDialog

问题描述

我正在开发一个用于读取 JSON 文件然后将其写入文件的 swing 应用程序。操作项将列在显示文件元数据的 JTable 行中,每行的最后一列都有一个按钮,用于将 JSON 打印到本地文件中。

在执行的操作中,我计划显示一个自定义 JDialog 以防止 UI 中的任何操作,这会阻止所有进一步的步骤,例如写入文件。

这是否可以在显示 JDialog 后启动一个线程来调用文件重新操作的函数?我使用 Thread 尝试过这种方式,但这也被阻止了。

@Override
    public void actionPerformed(ActionEvent e) {
        JButton printerButton = (JButton) e.getSource();
        String ac = printerButton.getActionCommand();
        System.out.println("ac = " + ac);
        
        /*
         * **Start JDialog for blocking any operation on the window** 
         */
        
        /*
         * **Start a thread for writing a file**
         */
    }

标签: javamultithreadingswingmodal-dialogjdialog

解决方案


推荐阅读