我有问题重新打开我的代码中的一个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