JInternalFrame Problem

I have created two JInternalFrame objects and placed them in a JDesktopPane. Only one JInternalFrame is visible at a time. I have a button that when clicked makes one disappear and the other become visible. It works the first time, but subsequently, when clicked, the same button does not make the second JInternalFrame appear a second time. All code compiles fine and works on the first shot.

JDesktopPane mainPane = new JDesktopPane();

Box box1 = new Box(BoxLayout.X_AXIS);

listFrame = new JInternalFrame("Liste des Titres de Film", true, true, true, true);

listFrame.setContentPane(box1);

listFrame.add(listScroller, BorderLayout.CENTER);

listFrame.setSize(430, 302);

listFrame.setVisible(true);

mainPane.add(listFrame);

genreLabel = new JLabel("Genre");

genreLabel.setForeground(Color.WHITE);

genreLabel.setBounds(150, 25, 100, 20);

yearLabel = new JLabel("Ann閑");

yearLabel.setForeground(Color.WHITE);

yearLabel.setBounds(150, 50, 100, 20);

titleLabel = new JLabel("Titre du Film");

titleLabel.setForeground(Color.WHITE);

titleLabel.setBounds(275, 75, 100, 20);

actorLabel = new JLabel("Nom de L'acteur");

actorLabel.setForeground(Color.WHITE);

actorLabel.setBounds(275, 100, 100, 20);

titleBox = new JTextField();

titleBox.setBounds(25, 75, 225, 20);

actorBox = new JTextField();

actorBox.setBounds(25, 100, 225, 20);

year = new JTextField();

genre = new JTextField();

year.setBounds(25, 50, 100, 20);

genre.setBounds(25, 25, 100, 20);

accepter = new JButton("Accepter");

accepter.setBounds(25, 130, 100, 25);

panel1 = new JPanel();

panel1.setLayout(null);

panel1.setBackground(new Color(0, 0, 51));

panel1.add(accepter);

panel1.add(titleBox);

panel1.add(actorBox);

panel1.add(year);

panel1.add(yearLabel);

panel1.add(genre);

panel1.add(genreLabel);

panel1.add(titleLabel);

panel1.add(actorLabel);

Box box2 = new Box(BoxLayout.X_AXIS);

addTitleFrame = new JInternalFrame("Ajouter un Titre de Film", true, true, true, true);

addTitleFrame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

addTitleFrame.setContentPane(box2);

addTitleFrame.add(panel1, BorderLayout.CENTER);

addTitleFrame.setSize(430, 302);

addTitleFrame.setVisible(false);

mainPane.add(addTitleFrame);

Code that fires action for JButton:

public void actionPerformed(ActionEvent ae) {

String label = ae.getActionCommand();

String title = titleBox.getText();

if(label.equals("Effacer Texte")) clearText();

else if(label.equals("Ajouter Titre")) { ///button to bring up second window

addTitleFrame.setVisible(true);

}

}

[2848 byte] By [henri_sergea] at [2007-10-2 0:53:13]
# 1
try using a flag variable which will tell which frame to display when clicked toggle the value and use other code to display a frme indicatedby the flag variableif u can do in this way many problems will be solved as one frame must be visible
i_virusa at 2007-7-15 18:12:58 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 2
Hi Henri,Try to use the method JInternalFrame.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE); instead of calling setVisible(false);That works for me!
dominwlaa at 2007-7-15 18:12:58 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 3

Hi

i made some modification in your code

public void actionPerformed(ActionEvent ae) {

String label = ae.getActionCommand();

String title = titleBox.getText();

if(label.equals("Effacer Texte")) clearText();

else if(label.equals("Ajouter Titre")) { ///button to bring up second window

addTitleFrame = new JInternalFrame("Ajouter un Titre de Film", true, true, true, true);

addTitleFrame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

addTitleFrame.setContentPane(box2);

addTitleFrame.add(panel1, BorderLayout.CENTER);

addTitleFrame.setSize(430, 302);

addTitleFrame.setSelected(true);

mainPane.add(addTitleFrame);

}

}

anburaja at 2007-7-15 18:12:58 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...