-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.4.1
-
x86
-
windows_2000
Name: jk109818 Date: 08/14/2003
FULL PRODUCT VERSION :
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
EXTRA RELEVANT SYSTEM CONFIGURATION :
Easiest to reproduce when screen resolution is 1024x768
A DESCRIPTION OF THE PROBLEM :
When using the GridBagLayout on a dialog containing two identical panels, each with a label and a scroll pane containing a list, the resizing behaviour of the window is unusual if the two panels have different text in their labels. When the window is resized, the two lists will not get horizontal scroll bars at the same point; that is, one list will get a horizontal scroll bar when the other will not.
Additionally, sometimes you can actually get a horizontal scrollbar to appear by adjusting the vertical size of the window, though this is more difficult to reproduce. When the window is short enough that both lists have a vertical scrollbar and narrow enough that one (or both) of the lists is almost at the point of getting a horizontal scroll bar, adjusting the vertical height will cause a horizontal scroll bar to appear.
Note that both of these problems seem dependent on the label text. If they both have the same label text, it will not happen, but if they have different labels (as shown in the example below), it will happen, though it only seems to occur with certain pairs of labels. This happens even when both labels are shorter than the width of the list, and regardless of whether both labels have the same number of characters.
Note that in the sample the cells are set to a fixed width in the list. This is not required to reproduce the problem, it just makes it easier to reproduce.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample code below. Note that both lists are the same width and have identical data, and the only difference between the two halves of the window is the label text. Make the window significantly shorter (until 7654321 is the bottom visible string is an easy place to reproduce). Both a vertical and horizontal scroll bar should appear.
1) Now slowly make the window wider (a few pixels at a time).
2) Slowly make the window longer/shorter
(These may take several attempts to reproduce, as there only seems to be a couple pixel margin in which these problems occur)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1) The horizontal scroll bar should disappear at the same time for both lists.
2) Adjusting the height of the window should not cause the list to get a horizontal scrollbar unless it also causes it to get a vertical scrollbar at the same time
ACTUAL -
1) Eventually the horizontal scroll bar will disappear for the right list but not the left list.
2) At a certain point the horizontal scrollbar may appear or disappear, even though the vertical scrollbar has not appeared or disappeared. If you used 7654321 as the point for adjusting the width, the point where the scrollbars appear and disappear should be around 654321 in left list. As well, the lists move a few pixels inside the dialog when the scrollbar appears/disappears. This may also occur right around the point where the vertical scrollbars disappear.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
There is no error messages; the behaviour is just unexpected.
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class ListTest extends JFrame
{
public static int COMP = 5;
public static int EDGE = 10;
public static int WIDTH = 125;
ListTest()
{
getContentPane().add( layoutControls() );
}
JPanel layoutControls()
{
JPanel p = new JPanel();
GridBagConstraints gbc = new GridBagConstraints();
p.setLayout( new GridBagLayout() );
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
gbc.weighty = 0.5;
p.add( getPanel( "Visible Columns:" ), gbc );
gbc.gridx++;
p.add( getPanel( "Hidden Columns:" ), gbc );
return p;
}
JPanel getPanel( String labelText )
{
JPanel p = new JPanel();
GridBagConstraints gbc = new GridBagConstraints();
p.setLayout( new GridBagLayout() );
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.NONE;
gbc.weightx = 1.0;
gbc.insets.top = EDGE;
gbc.insets.bottom = COMP;
gbc.insets.right = COMP;
gbc.insets.left = EDGE;
JLabel l = new JLabel( labelText );
p.add( l, gbc );
gbc.gridy++;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.insets.top = COMP;
gbc.insets.bottom = EDGE;
gbc.fill = GridBagConstraints.BOTH;
DefaultListModel model = new DefaultListModel();
JList list = new JList( model );
list.setFixedCellWidth( WIDTH );
l.setLabelFor( list );
addItems( model );
p.add( new JScrollPane( list ), gbc );
return p;
}
void addItems( DefaultListModel model )
{
for( int i = 13; i > 0; i--) {
String s = new String();
for( int j = i - 1; j > 0 ; j--){
s += j;
}
model.addElement( s );
}
}
public static void main( String[] args )
{
ListTest lt = new ListTest();
lt.setSize( 300, 300 );
lt.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } });
lt.setVisible( true );
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Giving both labels the same text will eliminate the problem, but that is not a practical solution.
(Incident Review ID: 186930)
======================================================================