JDK-4222531 : JOptionPane layout broken when list used to display options
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.1,1.2.2,1.3.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_nt
  • CPU: generic,x86
  • Submitted: 1999-03-22
  • Updated: 1999-10-13
  • Resolved: 1999-10-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.3.0 kestrelFixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description

Name: vi73552			Date: 03/22/99


The JOptionPane in the following sample program is laid out
badly. The dialog box needs to be dragged taller to make the
items lay out correctly. Initially, only the icon is visible. As
the box is made a bit taller, the top of the List Box becomes
visible. As the dialog box is dragged taller still, when the
buttons become visible, it suddenly snaps to the proper layout.


package tests;
import javax.swing.JOptionPane;

public class DialogBug
{
  public DialogBug(String choices[]) {
    String name = (String) JOptionPane.showInputDialog(null,
						       "Choice",
						       "Choose a number",
						       JOptionPane.QUESTION_MESSAGE,
						       null,
						       choices,
						       null);
    System.out.println(name + " chosen");
    System.exit(0);
  }

  public static void main(String args[]) {
    String theList[] = { "One", "Two", "Three", "Four", "Five",
			 "Six", "Seven", "Eight", "Nine", "Ten",
			 "Eleven", "twelve", "thirteen", "fourteen",
			 "fifteen", "sixteen", "seventeen", "eighteen",
			 "nineteen", "twenty" };
    new DialogBug(theList);
  }
}
(Review ID: 55867) 
======================================================================

Name: skT88420			Date: 09/09/99


a simple JOptionPane.showInputDialog with enough input choices
to cause a JList to be used produces a dialog that is way too 
small.  not only is the dialog too short (only showing one line
of the JList), but it is also too narrow.  if the selected item
requires a horizontal scrollbar, that scroll bar now takes up
the entire visible area of the JScrollPane, and you can't even
see one item from the JList.  the following code illustrates
this behaviour.  (using default look and feel, metal).
--------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class OTest extends JFrame
{
    private static final String[] choices =
    {
        "let's start out with a really long string that could mess up",
        "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
        "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
        "seventeen", "eightteen", "nineteen", "twenty",
        "two thousand, three hundred and fifty-two", "2400"
    };

    private JButton open = new JButton("Open dialog");

    public OTest()
    {
        setSize(400, 300);
        setTitle("JOptionPane.showInputDialog Test");
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(open, BorderLayout.SOUTH);
        open.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                String sel = (String) JOptionPane.showInputDialog(OTest.this,
                    "Select an item.",
                    "All items", JOptionPane.PLAIN_MESSAGE,
                     null, choices, choices[0]);

                System.out.println(sel);
            }
        });
    }

    public static void main (String[] args)
    {
        new OTest().setVisible(true);
    }
}
----------------------------------------------------------------

resizing the dialog eventually shows the 10 lines of the JList
specified in the BasicOptionPaneUI, but only after resizing much
larger than is required to show that amount of text.

this seems like a *really* basic problem to have made it through
test.  has anyone else seen it?  it occurs with Sun 1.1.7, 1.1.8,
JRE 1.2.2, IBM 1.1.7, 1.1.8, and i'm using Swing 1.1.1 full
release.
(Review ID: 95065)
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: kestrel FIXED IN: kestrel INTEGRATED IN: kestrel
14-06-2004

WORK AROUND Name: vi73552 Date: 03/22/99 Choices with less than twenty elements seem to lay out properly. ====================================================================== Name: skT88420 Date: 09/09/99 haven't found one yet, other than not using JOptionPane. since i'm doing a custom LAF anyway, i'm trying to workaround in there, but haven't succeeded yet. (Review ID: 95065) ======================================================================
11-06-2004

EVALUATION It's true, when a very long list item is present, the horizontal scrollbar completely obscures the list. The JoptionPane is not laying out it's contents properly. Unfortunately at first glance it's not clear whether the problem lies in the OptionPaneUI, BoxLayout, ScrollPane, or the List!! may be related to 4192608. amy.fowler@Eng 1999-10-01 Digging deeper, it looks like this bug was caused by the JOptionPane workaround for 4135218 (dialogs created 2 pixels too small on NT in 1.1.6), which basically adjusted the preferredSize of the optionpane to accommodate this size limitation. Unfortunately, this workaround calculated the preferredSize BEFORE the optionpane had completely built itself, hence it stored a preferred size that in this case was way too small to display the list correctly: public static Object showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) { JOptionPane pane = new JOptionPane(message, messageType, OK_CANCEL_OPTION, icon, null, null); // Workaround for bug#4135218 pane.adjustPreferredSize(); <<<---- TOO EARLY! pane.setWantsInput(true); pane.setSelectionValues(selectionValues); pane.setInitialSelectionValue(initialSelectionValue); And, further investigation shows that the bug that this workaround was for is now fixed, so should just remove this workaround from the JOptionPane! amy.fowler@Eng 1999-10-04
04-10-1999