-
Bug
-
Resolution: Fixed
-
P3
-
1.2.2
-
beta
-
sparc
-
solaris_2.5.1
Name: aaC67449 Date: 01/17/99
JTabbedPane.indexOfTab(Icon) throws unexpected NullPointerException,
when there is a null icon in the list.
javadoc states:
"public int indexOfTab(Icon icon)
Returns the first tab index with a given icon.
Returns -1 if no tab has this icon.
Parameters:
icon - the icon for the tab
public void addTab(String title,
Icon icon,
Component component)
Adds a component represented by a title and/or icon,
either of which can be null. Cover method for <--
insertTab().
"
See example.
--------------- Example---------------------------
import javax.swing.*;
import java.awt.*;
public class Test {
public static void main(String argv[]) {
JTabbedPane c = new JTabbedPane();
Icon icons[] = { null, new StubIcon() };
for (int j = 0; j < icons.length; j++) {
c.addTab("" + j, icons[j], new JLabel("" + j)); // Fill the set
}
if (c.indexOfTab(icons[1]) == 1) { // Try to find through the null
System.out.println("Ok");
} else {
System.out.println("Failed ");
}
}
}
class StubIcon implements Icon {
public void paintIcon(Component c, Graphics g, int x, int y) {}
public int getIconWidth() {
return 0;
}
public int getIconHeight() {
return 0;
}
}
----------------output------------------
Exception in thread "main" java.lang.NullPointerException
at javax.swing.JTabbedPane.indexOfTab(JTabbedPane.java:950)
at Test.main(Test.java:13)
======================================================================