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

JOptionpane is using minimum message height for most components

XMLWordPrintable

      J2SE Version (please include all output from java -version flag):
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

      Does this problem occur on J2SE 1.4.x or 5.0.x or 6.0? Yes / No (pick one)
      Yes

      Operating System Configuration Information (be specific):
      Microsoft Windows XP [Version 5.1.2600]

      JOptionPane is using minimum message height for most components

      When the message components preferred height can not be satisfied the JOptionPane is only giving the message it's minimum height.
      In BasicOptionPaneUI.addMessageComponents there is a workaround for this problem, however that only fixes the problem when the message is a JScrollPane or a JPanel.

      1) Run Code
      2) Notice that the button is at it's minimum height (this is probably another bug, as the code uses pack(), hence the JOptionPane and Button should be at their preferred sizes)
      3) Resize the dialog to a larger height (at some point the button will jump in size to it's preferred height)
      4) Resize the dialog again to somewhere between the buttons minimum height and preferred height (at some point the button will jump in size to it's minimum height)

      If the available height is less than the buttons preferred height, it should be given all the available height, not just it's minimum height.

      import static javax.swing.JFrame.*;
      import java.awt.*;
      import javax.swing.*;

      public class Test {
        public static void main(String[] args) {
          JFrame frame = new JFrame();
          JDialog dialog = new JOptionPane(new JButton("Test") {
            public Dimension getPreferredSize() {
              return new Dimension(500, 500);
            }
          
            public Dimension getMinimumSize() {
              return new Dimension(50, 50);
            }
          }).createDialog(frame, "test");
          dialog.setResizable(true);
          dialog.setVisible(true);
          frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
          frame.pack();
          frame.setVisible(true);
        }
      }

            Unassigned Unassigned
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: