Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4222531

JOptionPane layout broken when list used to display options

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.3.0
    • 1.2.1, 1.2.2, 1.3.0
    • client-libs
    • kestrel
    • generic, x86
    • generic, windows_nt



      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)
      ======================================================================

            amfowler Anne Fowler (Inactive)
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: