我有一个JFrame
(EC_GUI.main),然后我创建了几个JDialog
我添加了JPanel
,并将JFrame
作为所有者传递。
我现在正在检测是否通过JDialogs
打开了这些jFrame.getOwnedWindows()
中的任何一个,因为我无法通过其中一个
EC_GUI.main.getComponentCount() 1
javax.swing.JRootPane[,0,0,755x1005,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=]
EC_GUI.main.getRootPane().getComponentCount() 2
javax.swing.JPanel[null.glassPane,0,0,755x1005,hidden,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777217,maximumSize=,minimumSize=,preferredSize=]
javax.swing.JLayeredPane[null.layeredPane,0,0,755x1005,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,optimizedDrawingPossible=true]
EC_GUI.main.getContentPane().getComponentCount() 1
ec.gui.dialogs.template.EC_BorderPanel[,0,0,755x1005,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.EmptyBorder@44e6097c,flags=9,maximumSize=,minimumSize=,preferredSize=]
但是如果我查询ownedWindows
EC_GUI.main.getOwnedWindows().length 1
ec.gui.dialogs.visivilityfield.EC_VrPresetDialog$1[dialog0,385,254,502x511,invalid,hidden,layout=java.awt.BorderLayout,MODELESS,title=Virtual Reality Presets,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,502x511,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
我注意到,即使我打电话给jDialog.dispose()
我仍然有参考,所以如果我打开和关闭,让我们说3次,我的一个JDialog
,我得到
EC_GUI.main.getOwnedWindows().length 3
ec.gui.dialogs.visivilityfield.EC_VrPresetDialog$1[dialog1,385,254,502x511,invalid,hidden,layout=java.awt.BorderLayout,MODELESS,title=Virtual Reality Presets,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,502x511,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
ec.gui.dialogs.visivilityfield.EC_VrPresetDialog$1[dialog2,385,254,502x511,invalid,hidden,layout=java.awt.BorderLayout,MODELESS,title=Virtual Reality Presets,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,502x511,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
ec.gui.dialogs.visivilityfield.EC_VrPresetDialog$1[dialog3,385,254,502x511,invalid,hidden,layout=java.awt.BorderLayout,MODELESS,title=Virtual Reality Presets,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,502x511,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
这是正常的吗?
答案 0 :(得分:0)
你读完JavaDocs你不会那样,当配置正确时,dispose将释放窗口正在使用的本机资源,这不会“处置”对象,你可以重新显示窗口通过调用setVisible。
您可以查看isDisplayable
(如果窗口仍然有对其本地对等方的引用,则会通知您)或更可靠的isVisible
选项......
如果对话框没有其他强引用,它最终将被垃圾收集。