我有問題重新打開我的代碼中的一個JInternalFrame。我在MenuBar選項「Cadastro」 - >「Cadastro deVeículos」中選擇,此操作打開一個屏幕插入車輛。但是,如果我關閉此屏幕並嘗試重新打開它,我再也不能。重新打開JDesktopPane/JFrame上的JInternalFrame
下面是我正在使用的兩個代碼。
首先,JMain(這是我的JFrame):
import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyVetoException; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.WindowConstants; import javax.swing.event.InternalFrameListener; public class JMain extends JFrame implements ActionListener{ /** * Create the panel. */ private JMenuBar menuBar = new JMenuBar(); private JMenu firstMenu = new JMenu("Cadastro"); private JMenu secndMenu = new JMenu("Indicadores"); private JMenu thirdMenu = new JMenu("Agendamentos"); private JMenu fourthMenu = new JMenu("Relatórios"); private JMenuItem cadVeiculos = new JMenuItem("Cadastro de Veículos"); private JMenuItem cadMotoristas = new JMenuItem("Cadastro de Motoristas"); private JMenuItem cadCargas = new JMenuItem("Cadastro de Cargas"); private JMenuItem newExit = new JMenuItem("Sair"); public JDesktopPane jdPane = new JDesktopPane(); JCadVeiculos telaCadVeiculos; public static void main (String args []){ JMain jmain = new JMain(); } public JMain() { jdPane.setBackground(Color.LIGHT_GRAY); setTitle("Gtrix - Version 0.1"); setSize(600, 500); getContentPane().add(jdPane); setJMenuBar(menuBar); menuBar.add(firstMenu); menuBar.add(secndMenu); menuBar.add(thirdMenu); menuBar.add(fourthMenu); firstMenu.add(cadVeiculos); firstMenu.add(cadMotoristas); firstMenu.add(cadCargas); firstMenu.addSeparator(); firstMenu.add(newExit); cadVeiculos.addActionListener(this); setVisible(true); } public void actionPerformed(ActionEvent evt) { if(evt.getSource() == cadVeiculos){ if(telaCadVeiculos == null){ telaCadVeiculos = new JCadVeiculos(this); } //telaCadVeiculos.show(); //telaCadVeiculos.setDefaultCloseOperation(JCadVeiculos.DO_NOTHING_ON_CLOSE); jdPane.moveToFront(telaCadVeiculos); } } }
和JCadVeiculos(我的JInternalFrame):
package ui;
import java.awt.EventQueue;
import java.awt.Menu;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
public class JCadVeiculos extends JInternalFrame {
private JMain telaPrincipal;
/**
* Create the frame.
*/
public JCadVeiculos(JMain telaPrincipal) {
super("", true, true, false);
setSize(600,500);
setTitle("Cadastro de Veículos");
setVisible(true);
this.telaPrincipal = telaPrincipal;
telaPrincipal.jdPane.add(this);
}
}
請幫幫我! :)
我真的會閱讀更多關於這個鏈接,您發佈的上下文中初始化你的用戶界面,因爲我不不明白你對我的解釋。如果我找到一個解決方案,我會在這裏發佈。 謝謝! – user1930634
真的嗎?我不認爲當你關閉它時,它隱藏了(setVisible(false)),所以你需要再次顯示它(setVisible(true)) – MadProgrammer