FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)
<verified in all subsequent runtimes>
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When programmatically setting the selected index, the Tabbed Pane does not correctly set visiblity on its components within the tabs to allow the selected tab to be visible. This is true even when selection code is executed within the dispatch thread.
@bug 4459110 appears to be similar to this report, but dismissed due to dispatch thread.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the included program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The displayed component Should be Blue (The component at index 2)
ACTUAL -
The Displayed component is Green (the component at index 1)
By clicking on index 1, then index 2 again, the correct component is displayed
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
/**
*
*/
public class ITabControlTest
{
public static void main(String[] args)
{
Runnable runner = new Runnable()
{
public void run()
{
JFrame frame = new JFrame();
frame.setTitle("setSelectedIndex Bug");
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
JTabbedPane foo = new JTabbedPane();
// ITabControl foo = new ITabControl();
JPanel a = buildComplex(Color.RED);
JPanel b = buildComplex(Color.GREEN);
JPanel c = buildComplex(Color.BLUE);
foo.add(a, 0);
foo.add(b, 1);
foo.add(c, 2);
frame.getContentPane().add(foo);
frame.pack();
frame.show();
foo.setSelectedIndex(0);
foo.setComponentAt(0,(Component)new JPanel());
foo.setComponentAt(0, a);
foo.setSelectedIndex(1);
foo.setComponentAt(1,(Component)new JPanel());
foo.setComponentAt(1, b);
foo.setSelectedIndex(2);
foo.setComponentAt(2,(Component)new JPanel());
foo.setComponentAt(2, c);
foo.setSelectedIndex(0);
foo.setSelectedIndex(2);
}
};
SwingUtilities.invokeLater(runner);
}
private static JPanel buildComplex(Color p_color)
{
JPanel pan = new JPanel();
pan.setPreferredSize(new Dimension(300,300));
pan.setBackground(p_color);
return pan;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I am not sure this works around all facets of this bug, but:
in subclass of JTabbedPane:
public void setSelectedIndex()
{
Component comp = getSelectedComponent();
if(comp != null)
comp.setVisible(false);
super.setSelectedIndex(p_index);
}
###@###.### 2005-06-14 06:20:33 GMT