我在使用时创建了MDI
(多文档界面),其中我有两个 jbuttons 和一个 jdesktoppane,所以当单击两个按钮时,两个 jinternalframes 都在同一个 jdesktoppane 中打开,所以我想在什么时候打开?java
netbeans
close previous jinternalframe
open new jinternalframe
jdesktoppane
检查快照以更好地了解我的问题我想要什么...
第一个 jButton 代码:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
tst t = new tst();
JInternalFrame internalFrame1 = new JInternalFrame("Test Window1");
internalFrame1.add(t.getContentPane());
internalFrame1.pack();
internalFrame1.setVisible(true);
q.add(internalFrame1);
internalFrame1.setClosable(true);
BasicInternalFrameUI ui = (BasicInternalFrameUI)internalFrame1.getUI();
Container north = (Container)ui.getNorthPane();
north.remove(0);
north.validate();
north.repaint();
for(MouseListener listener : ((javax.swing.plaf.basic.BasicInternalFrameUI) internalFrame1.getUI()).getNorthPane().getMouseListeners()){
((javax.swing.plaf.basic.BasicInternalFrameUI) internalFrame1.getUI()).getNorthPane().removeMouseListener(listener);
}
internalFrame1.setSelected(true);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, ex);
}
}
第二个按钮代码:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
zxy z = new zxy();
JInternalFrame internalFrame = new JInternalFrame("Test Window2");
internalFrame.add(z.getContentPane());
internalFrame.pack();
internalFrame.setSize(570,420);
internalFrame.setVisible(true);
q.add(internalFrame);
internalFrame.setClosable(true);
BasicInternalFrameUI ui = (BasicInternalFrameUI)internalFrame.getUI();
Container north = (Container)ui.getNorthPane();
north.remove(0);
north.validate();
north.repaint();
for(MouseListener listener : ((javax.swing.plaf.basic.BasicInternalFrameUI) internalFrame.getUI()).getNorthPane().getMouseListeners()){
((javax.swing.plaf.basic.BasicInternalFrameUI) internalFrame.getUI()).getNorthPane().removeMouseListener(listener);
}
internalFrame.setSelected(true);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, ex);
}
}