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

Requested JDialog width is ignored

XMLWordPrintable

    • b13
    • x86_64
    • windows_10

        ADDITIONAL SYSTEM INFORMATION :
        Tested under jdk-10 and 12.

        A DESCRIPTION OF THE PROBLEM :
        Although a JDialog can manually be narrowed to a minimum width of 132, any pro-
        grammatically requested dialog width less than 198 is ignored and set to 198.
        When running the code example below, one can defer from the asymetric placing of
        the dialog, that still somewhere the requested width is taken into into account.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile and run the code.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        JDialog should have a width of 150.
        ACTUAL -
        Width is 198.

        ---------- BEGIN SOURCE ----------
        import java.awt.*;
        import javax.swing.*;

        public class NarrowDialog extends JFrame {

          public NarrowDialog() {
            setSize(300,350);
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setLocationRelativeTo(null);
            setTitle("JFrame");
            setVisible(true);

            JDialog dlg= new JDialog(this, "JDialog", true);
            dlg.setSize(150, 200);
        // dlg.setResizable(false);
        /* No change when specifying all sizes.
            Dimension dim= new Dimension(150, 200);
            dlg.setMaximumSize(dim);
            dlg.setMinimumSize(dim);
            dlg.setPreferredSize(dim);
        */
            dlg.setLocationRelativeTo(this);
            dlg.setVisible(true);
            System.out.println(dlg.getSize());
          }


          public static void main(String args[]) {
            SwingUtilities.invokeLater(NarrowDialog::new);
          }

        }

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

        FREQUENCY : always


              serb Sergey Bylokhov
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: