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

JFrame being moved down when calling setSize when setResizable is false

XMLWordPrintable

    • x86_64
    • linux_ubuntu

      FULL PRODUCT VERSION :
      java version "1.7.0_95"
      OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.14.04.2)
      OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux Wall-E 3.13.0-35-generic #62-Ubuntu SMP Fri Aug 15 01:58:42 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux


      EXTRA RELEVANT SYSTEM CONFIGURATION :
      unity 7.2.6

      A DESCRIPTION OF THE PROBLEM :
      If a Frame is set not resizable with the setResizable(false) command, each call to setSize on the frame will move the frame 10 pixels down.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just execute the test case on Ubuntu with Unity (I don't know about other configurations)

      In short, create a JFrame, call setResizable(false), and then every call to setSize will move the frame 28 pixels down.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The frame width is suppose to increase to fit the JTextArea.
      ACTUAL -
      Each time the frame width increases, the frame is being moved 28 pixels lower for no reason.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      This is the stacktrace of the ComponentMoved method :

      at test.Test2$1$3.componentMoved(Test2.java:50)
      at java.awt.AWTEventMulticaster.componentMoved(AWTEventMulticaster.java:169)
      at java.awt.AWTEventMulticaster.componentMoved(AWTEventMulticaster.java:169)
      at java.awt.Component.processComponentEvent(Component.java:6345)
      at java.awt.Component.processEvent(Component.java:6296)
      at java.awt.Container.processEvent(Container.java:2229)
      at java.awt.Window.processEvent(Window.java:2022)
      at java.awt.Component.dispatchEventImpl(Component.java:4872)
      at java.awt.Container.dispatchEventImpl(Container.java:2287)
      at java.awt.Window.dispatchEventImpl(Window.java:2719)
      at java.awt.Component.dispatchEvent(Component.java:4698)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
      at java.awt.EventQueue.access$300(EventQueue.java:103)
      at java.awt.EventQueue$3.run(EventQueue.java:706)
      at java.awt.EventQueue$3.run(EventQueue.java:704)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:77)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
      at java.awt.EventQueue$4.run(EventQueue.java:720)
      at java.awt.EventQueue$4.run(EventQueue.java:718)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:77)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;

      import java.awt.BorderLayout;
      import java.awt.Dimension;
      import javax.swing.JFrame;
      import javax.swing.JTextArea;
      import javax.swing.SwingUtilities;
      import javax.swing.text.AbstractDocument;
      import javax.swing.text.AttributeSet;
      import javax.swing.text.BadLocationException;
      import javax.swing.text.DocumentFilter;

      public class Test2 {
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      final JFrame mainFrame = new JFrame("test");
                      mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      mainFrame.setResizable(false);
                      final JTextArea field = new JTextArea() {
                          public Dimension getPreferredSize() {
                              Dimension pref = super.getPreferredSize();
                              return new Dimension(Math.max(30, pref.width),Math.max(20, pref.height));
                          }
                      };
                      ((AbstractDocument)field.getDocument()).setDocumentFilter(new DocumentFilter() {
                          @Override
                          public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
                              super.replace(fb, offset, length, text, attrs);
                              //We make the frame fit the content. We can use pack as well with the same result
                              mainFrame.setSize(mainFrame.getContentPane().getPreferredSize());
                              //mainFrame.pack();(same result with pack)
                              System.out.println(mainFrame.getLocation().y);//The frame is moving down when typing
                          }
                      });
                      mainFrame.getContentPane().setLayout(new BorderLayout());
                      mainFrame.getContentPane().add(field,BorderLayout.CENTER);
                      mainFrame.pack();
                      mainFrame.setVisible(true);
                  }
              });
          }

      }
      ---------- END SOURCE ----------

            ssadetsky Semyon Sadetsky (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: