swing中模态对话框(setModal(true))和显示对话框(setVisible(true))的编写顺序
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                swing中模态对话框(setModal(true))和显示对话框(setVisible(true))的编写顺序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                今天給大家分享一個鄙人在編程中總結出的一個易錯點和最容易讓人感到困惑的一個知識點:
 當你要從一個窗體跳轉到另一個窗體,你把跳轉目標的窗體設成模態對話框,設計成模態對話框就是禁止父窗體與子窗體之間操作,簡單說就是當調用子窗體的時候,父窗體不能使用,必須等子窗體銷毀才能使用,但是在這里會有個容易出錯的地方就是子窗體不能正常現實出來,而是顯示一個圓點,也就是下圖這種格式
 為什么會出現這種情況呢?剛開始我也有些疑惑,后來靈機一動,把setModal(true)放在setVisible(true)的后面,竟然發現解決了這個問題。
 還有就是 javasetModal(true) 要在dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);的后面,否則將無法關閉子對話框
正確寫法
public class EmployeeRegisterFrame extends JDialog {private JTextField accountField;private JTextField phoneField;private JPasswordField passwordField;public EmployeeRegisterFrame() {try {setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);**setVisible(true);**setResizable(false);**setModal(true);**} catch (Exception e) {e.printStackTrace();}setSize( 581, 420);setLocationRelativeTo(null);getContentPane().setLayout(null);錯誤寫法
public class EmployeeRegisterFrame extends JDialog {private JTextField accountField;private JTextField phoneField;private JPasswordField passwordField;public EmployeeRegisterFrame() {try {**setModal(true);**setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);**setVisible(true)**;setResizable(false);} catch (Exception e) {e.printStackTrace();}setSize( 581, 420);setLocationRelativeTo(null);getContentPane().setLayout(null); 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的swing中模态对话框(setModal(true))和显示对话框(setVisible(true))的编写顺序的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: ant-design-vue 环境搭建及
- 下一篇: html-图像标签
