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

Function pack() sizes JFrame and JDialog out of the vertical bounds.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 6u10
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_11"
      Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
      Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      When components are added to a JDialog or JFrame one under the other and the total preferred height of these components adds up to number bigger than the screen resolution's height, the JDialog's height is not calculated correctly and it does not take into account the screen insets. Therefore part of the dialog cannot be seen because it is hidden by the Windows' taskbar.

      On my tests with a screen resolution of [width=1920,height=1200] and after the pack() function is executed the dialog's size is [width=195,height=1212], that is, 12 pixels more than the screen resolution.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JDialog with a BorderLayout.
      Add 100 JLabels one under the other using a GridBagLayout to the CENTER of the layout.
      Add a JButton at SOUTH of the layout.
      Then call the pack() function and show the JDialog.
      Part of the JDialog cannot be seen because is hidden by the Windows' taskbar and the JButton cannot be seen.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The pack() function should take into account the screen's insets.
      ACTUAL -
        Toolkit.getDefaultToolkit().getScreenSize(): java.awt.Dimension[width=1920,height=1200]
        Toolkit.getDefaultToolkit().getScreenInsets(gd.getDefaultConfiguration()): java.awt.Insets[top=0,left=0,bottom=30,right=0]
      getSize(): java.awt.Dimension[width=195,height=1212]

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * BigDialog.java
       *
       * Created on: Jan 22, 2009
       *
       */
      package ui.dialog;

      import java.awt.*;

      import javax.swing.*;
      public class BigDialog extends JDialog
      {
          public BigDialog()
          {
              super();
              JPanel center = new JPanel(new GridBagLayout());
              GridBagConstraints gc = new GridBagConstraints();
              gc.weightx = 1;
              gc.weighty = 1;
              gc.fill = GridBagConstraints.BOTH;
              gc.anchor = GridBagConstraints.NORTHWEST;
              gc.gridwidth = GridBagConstraints.REMAINDER;
              for (int i=0;i<100;i++)
              {
                  center.add(new JLabel("Label " + i),gc);
              }
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(center,BorderLayout.CENTER);
              getContentPane().add(new JButton("This button cannot be seen"),BorderLayout.SOUTH);
              pack();
              setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

              // Output screen dimensions and insets.
              GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
              GraphicsDevice gd = ge.getDefaultScreenDevice();
              Insets ins = Toolkit.getDefaultToolkit().getScreenInsets(gd.getDefaultConfiguration());
              System.out.println("Toolkit.getDefaultToolkit().getScreenSize(): " +
                  Toolkit.getDefaultToolkit().getScreenSize());
              System.out.println("Toolkit.getDefaultToolkit().getScreenInsets(gd.getDefaultConfiguration()): "+ins);
              System.out.println("getSize(): "+getSize());
              System.out.println("Java version: " +System.getProperty("java.vm.version"));
          }
          /**
           * @param args
           */
          public static void main(String[] args)
          {
              new BigDialog().setVisible(true);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      You may override the pack() function like this:

          @Override
          public void pack()
          {
              super.pack();
              Insets ins = Toolkit.getDefaultToolkit().getScreenInsets(getGraphicsConfiguration().getDevice().getDefaultConfiguration());
              Rectangle rec = getGraphicsConfiguration().getBounds();
              Dimension dim = super.getSize();
              super.setSize(dim.width,rec.height-ins.top-ins.bottom);
          }

        Attachments

          Activity

            People

            Assignee:
            anthony Anthony Petrov (Inactive)
            Reporter:
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: