-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.5
-
generic
-
generic
Name: dgC58589 Date: 01/22/98
I subclassed JTabbedPane and overloaded the setSelectedIndex method as follow:
public void setSelectedIndex(int theIndex)
{
Component c = getSelectedComponent();
...
}
When the JTabbedPane is first created it calls the setSelectedIndex method. At this point there is not currently selected component. I would expect getSelectedComponent to return null but instead it throws an exception. The source code for JTabbedPane.getSelectedComponent is:
return getComponentAt(getSelectedIndex());
Since getSelectedIndex returns -1 at this point it is getComponentAt that throws the exception.
I would rewrite getSelectedComponent as:
Component c = null;
int i = getSelectedIndex();
if (i != -1)
c = getComponentAt(i);
return c;
(Review ID: 23769)
======================================================================
- duplicates
-
JDK-4108103 java.lang.ArrayIndexOutOfBoundsException thrown while creating JTabbedPane bean
-
- Closed
-