#6 Dynamically removing a component runs into Exception/System.

open
nobody
None
5
2014-08-24
2008-07-18
oraether
No

Dynamically removing a component runs into an

IllegalComponentStateException/no focus-traversable components inside this Container

The following code is a testcase for this bug:
Pressing the "action" button did it.

-------------------------------------------------------

import charva.awt.BorderLayout;
import charva.awt.event.ActionEvent;
import charva.awt.event.ActionListener;
import charvax.swing.JButton;
import charvax.swing.JFrame;
import charvax.swing.JPanel;

public class Testcase05 extends JFrame implements ActionListener {
private JPanel swingPanel1,swingPanel2, currentPanel, cont;
public Testcase05() {
super();
this.setTitle("Hello World Again !");
this.setSize(80, 24);
this.setLayout(new BorderLayout());

cont = new JPanel();
swingPanel1 = new JPanel();
swingPanel1.add(new JButton("11 Panel 11"));
swingPanel2 = new JPanel();
swingPanel2.add(new JButton("22 Panel 22"));
currentPanel = swingPanel1;
cont.add(currentPanel);
this.add(cont,BorderLayout.CENTER);
JPanel panel = new JPanel();

JButton but = new JButton("action");
but.addActionListener(this);
panel.add(but);
this.add(panel, BorderLayout.SOUTH);
this.setVisible(true);
}

public void actionPerformed(ActionEvent ae_) {
cont.remove(currentPanel);
if(currentPanel == swingPanel1)
currentPanel = swingPanel2;
else
currentPanel = swingPanel1;
cont.add(currentPanel,BorderLayout.CENTER);
}

public static void main(String[] args)
{
Testcase05 ts = new Testcase05();
}
}

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks