FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b136)
Java HotSpot(TM) Client VM (build 21.0-b06, mixed mode, sharing)
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 ----------
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 MultiScreenTest extends JFrame
{
public static void main(String[] args) throws Exception
{
EventQueue.invokeLater(new Runnable(){
public void run()
{
try
{
JFrame.setDefaultLookAndFeelDecorated(true);
new MultiScreenTest();
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
}
public MultiScreenTest() 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 ----------