-
Bug
-
Resolution: Unresolved
-
P3
-
7u5
-
linux
FULL PRODUCT VERSION :
java version " 1.7.0_05 "
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux ACR8X 3.2.0-36-generic #57-Ubuntu SMP Tue Jan 8 21:44:52 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
A JLabel containing HTML-text automatically wraps lines using the available space. If one adds that JLabel to a JSrollPane he has to set the preferredSize to a decent value otherwise it won`t wrap. All this should work fine along other Components inside a JPanel using a LayoutManager.
Cause I want a resizeable application window I extended JScrollPane to keep track of the resize events and dynamically change the size synced to the width of the viewport. (see WrapScrollPane.componentResized in test case code) Basically it works but sometimes the calculation of the preferred height by the layout manager is wrong (height value too big).
I have tried invalidating and revalidating after every step.
Delegating to the EventDispatchingThread didn`t help either.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Run test case
2) Broaden the window. Usually you have to play around a bit resizing and scrolling the window.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No gaps between text and boders of JLabels as long vertical scrollbar is present.
ACTUAL -
Sometimes you will recognize a gap between text and red border at top and bottom of the JLabels although vertical scrollbar is present. This happens if you broaden the window.
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
public class WrappedLabel implements Runnable {
private static final String DUMMY_TXT = " Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? " ;
public static void main( String[] args ){
SwingUtilities.invokeLater( new WrappedLabel() );
}
@Override
public void run(){
final JPanel panel = new JPanel( new GridBagLayout() );
final GridBagConstraints gc = new GridBagConstraints();
gc.fill = GridBagConstraints.BOTH;
gc.weightx = 1.0;
gc.weighty = 1.0;
{
gc.gridx = 0;
gc.gridy = 0;
final JLabel label = new JLabel( " <html> " + DUMMY_TXT );
label.setBorder( BorderFactory.createLineBorder( Color.RED ) );
panel.add( label, gc );
}
{
gc.gridx = 0;
gc.gridy = 1;
final JLabel label = new JLabel( " <html> " + DUMMY_TXT );
label.setBorder( BorderFactory.createLineBorder( Color.RED ) );
panel.add( label, gc );
}
final JFrame frame = new JFrame();
frame.add( new WrapScrollPane( panel ) );
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
frame.setSize( 256, 256 );
frame.setVisible( true );
}
private class WrapScrollPane extends JScrollPane implements ComponentListener {
{
this.viewport.addComponentListener( this );
}
WrapScrollPane( Component view ){
super( view );
}
@Override
public void componentHidden( ComponentEvent ce ){
}
@Override
public void componentMoved( ComponentEvent ce ){
}
@Override
public void componentResized( ComponentEvent ce ){
assert( this.viewport == ce.getSource() );
final Component view = this.viewport.getView();
if( view instanceof Container ){
final int width = this.viewport.getExtentSize().width;
view.setPreferredSize( new Dimension( width, Integer.MAX_VALUE ) );
final Container v = (Container) view;
final int height = v.getLayout().preferredLayoutSize( v ).height;
view.setPreferredSize( new Dimension( width, height ) );
view.revalidate();
}
}
@Override
public void componentShown( ComponentEvent ce ){
}
}
}
---------- END SOURCE ----------
java version " 1.7.0_05 "
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux ACR8X 3.2.0-36-generic #57-Ubuntu SMP Tue Jan 8 21:44:52 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
A JLabel containing HTML-text automatically wraps lines using the available space. If one adds that JLabel to a JSrollPane he has to set the preferredSize to a decent value otherwise it won`t wrap. All this should work fine along other Components inside a JPanel using a LayoutManager.
Cause I want a resizeable application window I extended JScrollPane to keep track of the resize events and dynamically change the size synced to the width of the viewport. (see WrapScrollPane.componentResized in test case code) Basically it works but sometimes the calculation of the preferred height by the layout manager is wrong (height value too big).
I have tried invalidating and revalidating after every step.
Delegating to the EventDispatchingThread didn`t help either.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Run test case
2) Broaden the window. Usually you have to play around a bit resizing and scrolling the window.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No gaps between text and boders of JLabels as long vertical scrollbar is present.
ACTUAL -
Sometimes you will recognize a gap between text and red border at top and bottom of the JLabels although vertical scrollbar is present. This happens if you broaden the window.
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
public class WrappedLabel implements Runnable {
private static final String DUMMY_TXT = " Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur? " ;
public static void main( String[] args ){
SwingUtilities.invokeLater( new WrappedLabel() );
}
@Override
public void run(){
final JPanel panel = new JPanel( new GridBagLayout() );
final GridBagConstraints gc = new GridBagConstraints();
gc.fill = GridBagConstraints.BOTH;
gc.weightx = 1.0;
gc.weighty = 1.0;
{
gc.gridx = 0;
gc.gridy = 0;
final JLabel label = new JLabel( " <html> " + DUMMY_TXT );
label.setBorder( BorderFactory.createLineBorder( Color.RED ) );
panel.add( label, gc );
}
{
gc.gridx = 0;
gc.gridy = 1;
final JLabel label = new JLabel( " <html> " + DUMMY_TXT );
label.setBorder( BorderFactory.createLineBorder( Color.RED ) );
panel.add( label, gc );
}
final JFrame frame = new JFrame();
frame.add( new WrapScrollPane( panel ) );
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
frame.setSize( 256, 256 );
frame.setVisible( true );
}
private class WrapScrollPane extends JScrollPane implements ComponentListener {
{
this.viewport.addComponentListener( this );
}
WrapScrollPane( Component view ){
super( view );
}
@Override
public void componentHidden( ComponentEvent ce ){
}
@Override
public void componentMoved( ComponentEvent ce ){
}
@Override
public void componentResized( ComponentEvent ce ){
assert( this.viewport == ce.getSource() );
final Component view = this.viewport.getView();
if( view instanceof Container ){
final int width = this.viewport.getExtentSize().width;
view.setPreferredSize( new Dimension( width, Integer.MAX_VALUE ) );
final Container v = (Container) view;
final int height = v.getLayout().preferredLayoutSize( v ).height;
view.setPreferredSize( new Dimension( width, height ) );
view.revalidate();
}
}
@Override
public void componentShown( ComponentEvent ce ){
}
}
}
---------- END SOURCE ----------