Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a test case that helps to expose the problem.</p> <pre><code>import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import junit.framework.TestCase; public class JTabbedPaneTest extends TestCase { private JTabbedPane pane; private int count = 0; protected void setUp() throws Exception { pane = new JTabbedPane(); ChangeListener listener = new ChangeListener() { public void stateChanged(ChangeEvent e) { JTabbedPane pane = (JTabbedPane)e.getSource(); int before = count; count = pane.getTabCount(); System.out.println(String.format("%s --&gt; %s", before, count)); } }; pane.addChangeListener(listener); JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); pane.add(panel1); pane.add(panel2); } public void testOne() throws Exception { assertEquals(1, count); // I actually expect 2 assertEquals(2, pane.getTabCount()); pane.remove(0); pane.remove(0); assertEquals(0, count); assertEquals(0, pane.getTabCount()); } public void testMany() throws Exception { assertEquals(1, count); // I actually expect 2 assertEquals(2, pane.getTabCount()); pane.removeAll(); assertEquals(2, count); // I actually expect 0 assertEquals(0, pane.getTabCount()); } } </code></pre> <p>I think there is a synchronization issue going on; the output is:</p> <pre><code>0 --&gt; 1 1 --&gt; 1 1 --&gt; 0 0 --&gt; 1 1 --&gt; 2 </code></pre> <p>It looks as if some change events are being lost.</p> <p><strong>Update</strong>: leaving this in place for posterity, but it's wrong; as mmyers points out the events only fire when the selection changes.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload