JDK-7010721 : Frame#setMaximizedbounds not working properly on dual screen environment
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-01-06
  • Updated: 2017-03-08
  • Resolved: 2011-06-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b143Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b121)
Java HotSpot(TM) Client VM (build 20.0-b03, mixed mode)

A DESCRIPTION OF THE PROBLEM :
JFrame#setMaximizedBounds ist still not working properly on dual screen environment even if Bug 6699851 states that the issue has been fixed in Java7b121.

The intention is to respect existing task bars which means to respect the screen insets - to achieve this Bug 6899304 should be fixed too. Anyway, even without fixing the screen insets bug the frame size isn't correctly set when being modified just in the example below. Please also consider to fix related Bug 6899304.

see also http://www.java.net/forum/topic/jdk/java-se-snapshots-project-feedback/framesetmaximizedbounds-not-working-prop

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Setup your muti-screen environment (2 monitors), so that the resolution of screen 1 is less than screen 0 and Screen 0 is your main screen.
i.e. Screen Resolution for screen 0: 1920x1200
Screen Resolution for screen 1: 1680x1050

On my test system Java graphics configuration screen 0 is equivalent to Windows screen 2 and Java graphics configuration screen 0 is equivalent to Windows screen 2

The issue occurs only if screen resolution of screen 0 is less than screen 1
and screen 1 is the main screen or if screen resolution of screen 1 is less than screen 0 and screen 0 is the main screen

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The window for screen 0 should fill the complete screen except 40 pixel at the bottom - the same result is expected for screen 1.
ACTUAL -
The windows on screen 0 has the correct size - the window on screen 1 is too large. In the window title the expected size is displayed: width=1680, height=1010
The window content displays the real size: width=1920, height=1160

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
//see also http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6699851

import java.awt.EventQueue;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;

  public class MultiScreen6699851Test extends JFrame
  {
    public static void main(String[] args) throws Exception
    {
      EventQueue.invokeLater(new Runnable(){
        public void run()
        {
          try
          {
            JFrame.setDefaultLookAndFeelDecorated(true);
            new MultiScreen6699851Test();
          }
          catch(Exception e)
          {
            e.printStackTrace();
          }
        }
      });
    }

    public MultiScreen6699851Test() throws Exception
    {
      JPanel panel = new JPanel();
      BoxLayout layout = new BoxLayout(panel, BoxLayout.PAGE_AXIS);
      panel.setLayout(layout);
      panel.setBorder(new EmptyBorder(10,10,10,10));

      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsConfiguration dgc = ge.getDefaultScreenDevice().getDefaultConfiguration();
      System.err.println("Main-Screen bounds: " + dgc.getBounds());
      
      final GraphicsDevice[] gs = ge.getScreenDevices();
      for (int i = 0; i < gs.length; i++)
      {
        final int screen = i;
        JButton button = new JButton(new AbstractAction("Create window for screen " + i){
          public void actionPerformed(ActionEvent evt)
          {
            createFrame4Screen(gs, screen);
          }
        });
        panel.add(button);
        panel.add(Box.createVerticalStrut(10));
      }
      add(panel);
      
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setTitle(this.getClass().getSimpleName());
      pack();
      setLocationRelativeTo(null);
      setVisible(true);
    }
    
    private void createFrame4Screen(GraphicsDevice[] gs, int i)
    {
      JFrame f = new JFrame(gs[i].getDefaultConfiguration());
      GraphicsConfiguration gc = f.getGraphicsConfiguration();
      Rectangle maxBounds = gc.getBounds();
      
      //weird - decreasing height leads to increased frame size
      //only if screen resolution of screen 0 is less than screen 1
      //and screen 1 is the main screen
      //or if screen resolution of screen 1 is less than screen 0
      //and screen 0 is the main screen
      maxBounds.height -= 40;
      
      maxBounds.x=0;
      f.setMaximizedBounds(maxBounds);
      f.setTitle("Screen " + i + " " + maxBounds);
      f.setExtendedState(JFrame.MAXIMIZED_BOTH);
      f.setVisible(true);
      f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      
      JTextPane textPane= new JTextPane();
      textPane.setText("Frame bounds: " + f.getSize() + "\n");
      JScrollPane scroller = new JScrollPane(textPane);
      f.getContentPane().add(scroller);
    }
}

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

Comments
SUGGESTED FIX http://sa.sfbay.sun.com/projects/awt_data/7/7010721/
16-05-2011

EVALUATION The problem closely relates to the existing issue 6699851 fixed in JDK7. The difference between this issue and 6699851 is that: in 6699851 - the secondary monitor (that displays the window) is larger than the primary monitor in this issue - the primary monitor is larger than the secondary monitor The cause of the 6699851 is that the window manager adjusts these values to compensate for differences between the primary monitor and the monitor that displays the window. Taking into account this issue, it looks like the window manager adjusts these values only when the secondary monitor is larger than the primary monitor. What I see in this test (the primary monitor is larger) is that the window manager doesn't compensate the difference in this case. As a result, the unconditional changes for 6699851 becomes wrong. Moreover, with the fix 6699851 applied, it seems like the calculation gets wrong even when the the secondary monitor is larger than the primary monitor. The tested configuration is: monitor#1 - 1280x1024 monitor#2 - 1024x768 (primary screen) With the fix for 6699851, the newly calculated size equals to the size of the primary monitor and the window manager doesn't compensate the difference as well. So, the main question seems to be - when does the window manager compensate the difference between the monitors? The wording in the MSDN: "the window manager adjusts these values to compensate for differences between the primary monitor and the monitor that displays the window. Thus, if the user leaves ptMaxSize untouched, a window on a monitor larger than the primary monitor maximizes to the size of the larger monitor."
04-05-2011

EVALUATION I have finally a dual-screen setup of Windows XP, and may state that the issue is reproducible. On my second (and secondary) monitor there is no toolbar (and on any screen it presumably may be moved e.g. to the right from top to bottom) and the wrong size of the window is apparent. NB: screen resolution on the primary display is bigger than of secondary one (1280x1024 and 1024x748 resp. in my case), as stated in the description.
04-05-2011