-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0, 1.4.1
-
tiger
-
x86
-
windows_2000, windows_xp
Name: gm110360 Date: 05/30/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Occurs only when using
com.sun.java.swing.plaf.windows.WindowsLookAndFeel:
If one adds a component to a JButton, for example a JLabel,
and then calls pack() on the one of the containers of the
JButton the method
com.sun.java.swing.plaf.windows.WindowsButtonUI.getPreferred
Size will throw a NullPointerException since the line
"super.getPreferredSize"
in that method will eventually result in the code
if(b.getComponentCount() > 0) {
return null;
}
in
javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButton
Size and hence the Dimension object d in
com.sun.java.swing.plaf.windows.WindowsButtonUI.getPreferred
Size will be null when executing the lines
if (b.isFocusPainted()) {
if(d.width % 2 == 0) { d.width += 1; }
if(d.height % 2 == 0) { d.height += 1; }
}
and hence the NullPointerException.
(If you wonder why I want to add components to a JButton it
is because I want a JButton with two rows of text without
using a HTML-formatted string passed to the JButton.
Instead I create two JLabels and add them to the JButton
using a layout manager that puts one above the other.)
REGRESSION. Last worked in version 1.3.1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Use com.sun.java.swing.plaf.windows.WindowsLookAndFeel
2. Create a JFrame whose content pane contains a JButton
that contains, for example, a JLabel.
3. Call pack() on the JFrame
EXPECTED VERSUS ACTUAL BEHAVIOR :
The expected result is program termination with status "0",
instead the stack trace is printed and program is
terminated with status "1".
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
at com.sun.java.swing.plaf.windows.WindowsButtonUI.getPreferredSize
(WindowsButtonUI.java:123)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1262)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:564)
at java.awt.Container.preferredSize(Container.java:989)
at java.awt.Container.getPreferredSize(Container.java:973)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1264)
at javax.swing.JRootPane$RootLayout.preferredLayoutSize
(JRootPane.java:801)
at java.awt.Container.preferredSize(Container.java:989)
at java.awt.Container.getPreferredSize(Container.java:973)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1264)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:564)
at java.awt.Container.preferredSize(Container.java:989)
at java.awt.Container.getPreferredSize(Container.java:973)
at java.awt.Window.pack(Window.java:415)
at se.fyrplus.article.gui.Bug.main(Bug.java:34)
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.UIManager;
public class Bug
{
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel
("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
//UIManager.setLookAndFeel
("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
}
catch (Exception e)
{
e.printStackTrace();
}
JFrame frame = new JFrame();
JButton button = new JButton();
JLabel label = new JLabel("a label");
button.add(label);
frame.getContentPane().add(button);
try
{
frame.pack();
}
catch (NullPointerException e)
{
// caused when using com.sun.java.swing.plaf.windows.WindowsLookAndFeel
// in combination with JDK 1.4.0
e.printStackTrace();
System.exit(1);
}
System.exit(0);
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
There are three ways to work around the problem
1. Don't use JDK 1.4.0 but for example JDK 1.3.1_02
2. Don't use
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
3. Don't add components to JButton objects.
Release Regression From : 1.3.1_03
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Review ID: 147240)
======================================================================
Name: rmT116609 Date: 08/19/2002
FULL PRODUCT VERSION :
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When adding a JPanel to a JButton, a run time exception
occurs. Refer to the example code attached.
REGRESSION. Last worked in version 1.3.1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile the example class in the problem description
2. Run the class on a Windows XP machine.
EXPECTED VERSUS ACTUAL BEHAVIOR :
What should happen - a dialog appears with an empty button.
What does happen - run time exception
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
at
com.sun.java.swing.plaf.windows.WindowsButtonUI.getPreferredSize(WindowsButtonUI.java:123)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1272)
at java.awt.FlowLayout.preferredLayoutSize(FlowLayout.java:322)
at java.awt.Container.preferredSize(Container.java:1175)
at java.awt.Container.getPreferredSize(Container.java:1159)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1274)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:564)
at java.awt.Container.preferredSize(Container.java:1175)
at java.awt.Container.getPreferredSize(Container.java:1159)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1274)
at javax.swing.JRootPane$RootLayout.preferredLayoutSize(JRootPane.java:816)
at java.awt.Container.preferredSize(Container.java:1175)
at java.awt.Container.getPreferredSize(Container.java:1159)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1274)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:564)
at java.awt.Container.preferredSize(Container.java:1175)
at java.awt.Container.getPreferredSize(Container.java:1159)
at java.awt.Window.pack(Window.java:430)
at BUG.main(BUG.java:30)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
public class BUG
{
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
e.printStackTrace();
System.exit(0);
}
JButton btn = new JButton();
JPanel btnPanel = new JPanel();
btn.add(btnPanel);
JDialog dlg = new JDialog();
JPanel pnl = new JPanel();
dlg.getContentPane().add(pnl);
pnl.add(btn);
dlg.setModal(true);
dlg.pack();
dlg.show();
System.exit(0);
}
}
---------- END SOURCE ----------
(Review ID: 163318)
======================================================================
- duplicates
-
JDK-4738541 1.4.0 REGRESSION: NullPointerException in WindowsRadioButtonUI.getPreferredSize(
-
- Closed
-