Name: md23716 Date: 12/02/99
This is a duplicate of bug 4193302 which has been closed but not fixed.
Symptom:
When a long string is entered into a List and the window resized, the List width changes to that of the longest string in it.
This results in components to the right of the List being shifted right and squashed into the remaining space in the window.
If the window is not as wide as the List these components do not appear at all.
Test case available.
/* Class to demonstrate List box width problem */
public class ListBoxWidth2 implements java.awt.event.ActionListener {
private java.awt.Button ivjButton1 = null;
private java.awt.Button ivjButton2 = null;
private java.awt.Panel ivjContentsPane = null;
private java.awt.Frame ivjFrame1 = null;
private java.awt.List ivjList1 = null;
private java.awt.TextField ivjTextField1 = null;
public ListBoxWidth2() {
super();
initialize();
}
public void actionPerformed(java.awt.event.ActionEvent e) {
if ((e.getSource() == getButton1()) ) {
connEtoM1(e);
}
if ((e.getSource() == getButton2()) ) {
connEtoM2(e);
}
}
private void connEtoM1(java.awt.event.ActionEvent arg1) {
getList1().add(getTextField1().getSelectedText());
}
private void connEtoM2(java.awt.event.ActionEvent arg1) {
getList1().delItem(getList1().getSelectedIndex());
}
private void connEtoM2() {
getFrame1().show();
}
private java.awt.Button getButton1() {
if (ivjButton1 == null) {
ivjButton1 = new java.awt.Button();
ivjButton1.setName("Button1");
ivjButton1.setLabel("Add Selected Text");
};
return ivjButton1;
}
private java.awt.Button getButton2() {
if (ivjButton2 == null) {
ivjButton2 = new java.awt.Button();
ivjButton2.setName("Button2");
ivjButton2.setLabel("Remove");
};
return ivjButton2;
}
private java.awt.Panel getContentsPane() {
if (ivjContentsPane == null) {
ivjContentsPane = new java.awt.Panel();
ivjContentsPane.setName("ContentsPane");
ivjContentsPane.setLayout(new java.awt.BorderLayout());
getContentsPane().add(getList1(), "West");
/* Put the buttons in a panel */
java.awt.Panel pButtons = new java.awt.Panel();
pButtons.add( getButton1() );
pButtons.add( getButton2() );
getContentsPane().add( pButtons, "East");
getContentsPane().add(getTextField1(), "Center");
};
return ivjContentsPane;
}
private java.awt.Frame getFrame1() {
if (ivjFrame1 == null) {
ivjFrame1 = new java.awt.Frame();
ivjFrame1.setName("Frame1");
ivjFrame1.setLayout(new java.awt.BorderLayout());
ivjFrame1.setBounds(184, 158, 538, 240);
getFrame1().add(getContentsPane(), "Center");
};
return ivjFrame1;
}
private java.awt.List getList1() {
if (ivjList1 == null) {
ivjList1 = new java.awt.List();
ivjList1.setName("List1");
};
return ivjList1;
}
private java.awt.TextField getTextField1() {
if (ivjTextField1 == null) {
ivjTextField1 = new java.awt.TextField();
ivjTextField1.setName("TextField1");
};
return ivjTextField1;
}
private void initConnections() {
getButton1().addActionListener(this);
getButton2().addActionListener(this);
}
private void initialize() {
initConnections();
connEtoM2();
}
public static void main(java.lang.String[] args) {
try {
ListBoxWidth2 aListBoxWidth;
aListBoxWidth = new ListBoxWidth2();
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.lang.Object");
exception.printStackTrace(System.out);
}
}
}
To run:
java ListBoxWidth2
To exhibit the defect enter a long string (for instance cut and paste this line) into the middle pane (a TextField).
Select the string in the TextField.
Click 'Add Selected Text' button - this adds the selected text from the TextField to the List (in the left pane)
Resize the main window either horizontally or vertically.
The List resizes to the width of the string.
The window size can be restored if the string is removed from the List - select the string in the List and click the 'Remove' button
Resize the window again and the original proportions will be restored.
Note that simply moving the window does not cause the List to change width.
(Review ID: 98546)
======================================================================
This is a duplicate of bug 4193302 which has been closed but not fixed.
Symptom:
When a long string is entered into a List and the window resized, the List width changes to that of the longest string in it.
This results in components to the right of the List being shifted right and squashed into the remaining space in the window.
If the window is not as wide as the List these components do not appear at all.
Test case available.
/* Class to demonstrate List box width problem */
public class ListBoxWidth2 implements java.awt.event.ActionListener {
private java.awt.Button ivjButton1 = null;
private java.awt.Button ivjButton2 = null;
private java.awt.Panel ivjContentsPane = null;
private java.awt.Frame ivjFrame1 = null;
private java.awt.List ivjList1 = null;
private java.awt.TextField ivjTextField1 = null;
public ListBoxWidth2() {
super();
initialize();
}
public void actionPerformed(java.awt.event.ActionEvent e) {
if ((e.getSource() == getButton1()) ) {
connEtoM1(e);
}
if ((e.getSource() == getButton2()) ) {
connEtoM2(e);
}
}
private void connEtoM1(java.awt.event.ActionEvent arg1) {
getList1().add(getTextField1().getSelectedText());
}
private void connEtoM2(java.awt.event.ActionEvent arg1) {
getList1().delItem(getList1().getSelectedIndex());
}
private void connEtoM2() {
getFrame1().show();
}
private java.awt.Button getButton1() {
if (ivjButton1 == null) {
ivjButton1 = new java.awt.Button();
ivjButton1.setName("Button1");
ivjButton1.setLabel("Add Selected Text");
};
return ivjButton1;
}
private java.awt.Button getButton2() {
if (ivjButton2 == null) {
ivjButton2 = new java.awt.Button();
ivjButton2.setName("Button2");
ivjButton2.setLabel("Remove");
};
return ivjButton2;
}
private java.awt.Panel getContentsPane() {
if (ivjContentsPane == null) {
ivjContentsPane = new java.awt.Panel();
ivjContentsPane.setName("ContentsPane");
ivjContentsPane.setLayout(new java.awt.BorderLayout());
getContentsPane().add(getList1(), "West");
/* Put the buttons in a panel */
java.awt.Panel pButtons = new java.awt.Panel();
pButtons.add( getButton1() );
pButtons.add( getButton2() );
getContentsPane().add( pButtons, "East");
getContentsPane().add(getTextField1(), "Center");
};
return ivjContentsPane;
}
private java.awt.Frame getFrame1() {
if (ivjFrame1 == null) {
ivjFrame1 = new java.awt.Frame();
ivjFrame1.setName("Frame1");
ivjFrame1.setLayout(new java.awt.BorderLayout());
ivjFrame1.setBounds(184, 158, 538, 240);
getFrame1().add(getContentsPane(), "Center");
};
return ivjFrame1;
}
private java.awt.List getList1() {
if (ivjList1 == null) {
ivjList1 = new java.awt.List();
ivjList1.setName("List1");
};
return ivjList1;
}
private java.awt.TextField getTextField1() {
if (ivjTextField1 == null) {
ivjTextField1 = new java.awt.TextField();
ivjTextField1.setName("TextField1");
};
return ivjTextField1;
}
private void initConnections() {
getButton1().addActionListener(this);
getButton2().addActionListener(this);
}
private void initialize() {
initConnections();
connEtoM2();
}
public static void main(java.lang.String[] args) {
try {
ListBoxWidth2 aListBoxWidth;
aListBoxWidth = new ListBoxWidth2();
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.lang.Object");
exception.printStackTrace(System.out);
}
}
}
To run:
java ListBoxWidth2
To exhibit the defect enter a long string (for instance cut and paste this line) into the middle pane (a TextField).
Select the string in the TextField.
Click 'Add Selected Text' button - this adds the selected text from the TextField to the List (in the left pane)
Resize the main window either horizontally or vertically.
The List resizes to the width of the string.
The window size can be restored if the string is removed from the List - select the string in the List and click the 'Remove' button
Resize the window again and the original proportions will be restored.
Note that simply moving the window does not cause the List to change width.
(Review ID: 98546)
======================================================================