<Swing Dev> RfR: JDK-8133897, IndexOutOfBounds exception being thrown
Alexander Scherbatiy
alexandr.scherbatiy at oracle.com
Fri Aug 21 09:16:05 UTC 2015
The setTabComponentAt() method allows to set a component to a tabbed
pane title.
In the following example the tab title is "":
tabbedPane.addTab(null, new JLabel("Content 1"));
tabbedPane.setTabComponentAt(0, new JLabel("Title 1"));
The getBounds() method can also try to find a tab index by
tabComponent and by icon in case if indexOfTab(title) fails.
Thanks,
Alexandr.
On 8/20/2015 5:54 PM, Alexander Scherbatiy wrote:
> On 8/20/2015 12:50 AM, Pete Brunet wrote:
>> Please review this patch.
>> http://cr.openjdk.java.net/~ptbrunet/JDK-8133897/webrev.00/
>>
>> The issue is that the application has a tab with a visible title but
>> for some reason JTabbedPane's title field was "". This caused
>> indexOfTab(title) to return -1 and then getTabBounds(parent, -1)
>> raised ArrayIndexOutOfBoundsException.
>>
>>
>> public Rectangle getBounds() {
>> - return parent.getUI().getTabBounds(parent,
>> - parent.indexOfTab(title));
>> + int i = parent.indexOfTab(title);
>> + Rectangle r;
>> + // Check for no title. Even though that's a bug in the
>> app we should
>> + // inhibit an ArrayIndexOutOfBoundsException from
>> getTabBounds.
>> + if (i == -1) {
>> + r = null;
>> + } else {
>> + r = parent.getUI().getTabBounds(parent, i);
>> + }
>> + return r;
>> }
>>
>> Maybe someone more familiar with the code can see a bug related to
>> why title is allowed to be "" when there is a visible title displayed
>> in the tab. The bug I am working was raised during use of an app for
>> which we do not have access so its source is not available.
>
> It is possible to add icon with text so the title will be empty:
> tabbedPane.addTab(null, icon, new JLabel("Content").
> But even in this case indexOfTab returns the first tab with null
> title: tabbedPane.indexOfTab((String)null).
>
> Could it be that the tabbed pane title was changed between
> JTabbedPane.Page class creation and getBounds() method invoking?
>
> Thanks,
> Alexandr.
>>
>> Thanks, Pete
>
More information about the swing-dev
mailing list