FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b107)
Java HotSpot(TM) Client VM (build 19.0-b05, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
On Windows XP, the getBorder() method on javax.swing.border.TitledBorder returns null.
This is a regression - with java 6u21 and 1.7.0-ea-b36 it returns non-null.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached BorderTest sample.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Proper repainting, no exceptions.
ACTUAL -
Painting aborted with NullPointerException:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at MyBorder.paintBorder(MyBorder.java:17)
at javax.swing.JComponent.paintBorder(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at java.awt.Window.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$700(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.border.TitledBorder;
public class MyBorder extends TitledBorder
{
public MyBorder( String title )
{
super( title );
}
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height )
{
if ( getTitle() == null || getTitle().length() == 0 )
{
getBorder().paintBorder( c, g, EDGE_SPACING, EDGE_SPACING, width - 2 * EDGE_SPACING, height - 2 * EDGE_SPACING );
}
else
{
super.paintBorder( c, g, x, y, width, height );
}
}
}
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
public class BorderTest
{
public static void main( String[] args )
{
try
{
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
}
catch ( Exception e )
{
e.printStackTrace();
}
JFrame frame = new JFrame();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.getContentPane().setLayout( new FlowLayout() );
JLabel label1 = new JLabel( "Component with titled border" );
label1.setBorder( new MyBorder( "title" ) );
frame.getContentPane().add( label1 );
JLabel label2 = new JLabel( "Component with titled border - empty title" );
label2.setBorder( new MyBorder( "" ) );
frame.getContentPane().add( label2 );
frame.pack();
frame.setVisible( true );
}
}
---------- END SOURCE ----------