Name: rl43681 Date: 02/04/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b31)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b31, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Under certain conditions, BasicTabbedPaneUI will try to repaint a
tab that has already been removed, resulting in an exception.
This bug was apparently caused by the fix for bug #4895707. The
mousePressed() method relies solely on isRequestFocusEnabled() to
determine whether it should repaint the focus indicators, when it
should be calling isFocusable() as well.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Compile and run the sample code.
2) Click on the last tab (labelled "Four").
3) Use the button to delete the selected tab.
4) Click on any of the remaining tabs.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ArrayIndexOutOfBoundsException: 3
at javax.swing.plaf.basic.BasicTabbedPaneUI.getTabBounds
(BasicTabbedPaneUI.java:1295)
at javax.swing.plaf.basic.BasicTabbedPaneUI.getTabBounds
(BasicTabbedPaneUI.java:1235)
at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler
.mousePressed(BasicTabbedPaneUI.java:3198)
at java.awt.Component.processMouseEvent(Component.java:5460)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*; import javax.swing.*;
public class TabbedPaneDemo {
public static void main(String[] args)
{
JFrame frame = new JFrame("TabbedPaneDemo");
frame.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
final JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setFocusable(false);
tabbedPane.addTab("One", makeTextPanel("Panel 1"));
tabbedPane.addTab("Two", makeTextPanel("Panel 2"));
tabbedPane.addTab("Three", makeTextPanel("Panel 3"));
tabbedPane.addTab("Four", makeTextPanel("Panel 4"));
frame.getContentPane().add(tabbedPane,
BorderLayout.CENTER);
JButton button = new JButton("Remove Current Tab");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
int index = tabbedPane.getSelectedIndex();
if (index >= 0)
{
tabbedPane.removeTabAt(index);
}
}
});
frame.getContentPane().add(button,
BorderLayout.SOUTH);
frame.setSize(400, 150);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
static Component makeTextPanel(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use setRequestFocusEnabled(false) instead of setFocusable(false)
if you don't want the tabs to get keyboard focus.
(Incident Review ID: 235312)
======================================================================