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

JoptionPane.showInputDialog : wrong layout of JList if first element is empty

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0_06"
      Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
      Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]
      Same problem on Linux

      A DESCRIPTION OF THE PROBLEM :
      JoptionPane.showInputDialog()
      This bug occurs if :
      - selectionValues contains at least 20 elements
      - selectionValues first element is null or empty string

      if selectionValues has less than 20 elements a JComboBox is dislayed and the layout is OK.
      if selectionValues has 20 elements or more a JList is displayed instead of the JComboBox. If the first element of the list is null or empty the height of the JList is only one line (not correct). If the first element of the list is not null or empty, the JList has a height of 10 elements (correct).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) create an array of objects containing at least 20 elements
      2) set the first element to null or empty string
      3) set other elements to any value
      4) call JOptionPane.showInputDialog passing the array as the selectionValues argument

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A dialog with a JList of height = 10 elements.
      ACTUAL -
      A dialog with a JList of height = 1 element.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      no crash.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JOptionPane;
      import javax.swing.SwingUtilities;

      public class Test {

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {

                  public void run() {
                      Object[] choices = new Object[25];
                      choices[0] = ""; // or null
                      for (int i = 1; i < choices.length; i++) {
                          choices[i] = "choice " + i;
                      }

                      JOptionPane.showInputDialog(null,
                              "Select an item",
                              "Item selection",
                              JOptionPane.PLAIN_MESSAGE,
                              null,
                              choices,
                              choices[0]);
                  }
              });
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      replace the first value of the list with " " (one space character).
      Then replace the result with null or "" if the choice is " ".
      There still be a problem if an other element of the list has the value " ". I don't know if the result is null or "", or if the result is " ".

            Unassigned Unassigned
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: