The overall objective is to open a Window on both monitors that is located at the bottom area of the monitor without being covered by the Task Bar.
The sample below opens a JFrame on each of the 2 monitors. At the bottom of each is a JLabel "Can you read this???" which is not visible because it is covered by the Task Bar.
It seems sometimes the JFrame takes into account that the Task Bar is there and adjusts it accordingly but other times it does not.
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class WindowBorderTest
{
public static void main(String[] args)
{
runProgram();
}
private static void runProgram()
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
for (int j = 0; j < gs.length; j++)
{
GraphicsDevice gd = gs[j];
JFrame frame = new JFrame(gd.getDefaultConfiguration());
JLabel xLabel = new JLabel ("Can you read this???");
frame.setTitle("I'm on monitor #" + j);
frame.setSize(400,200);
frame.add(new JPanel() {
@Override
public Dimension getPreferredSize() {
return new Dimension(320, 240);
}
});
frame.getContentPane().add(xLabel, BorderLayout.PAGE_END);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Rectangle rect = gs[j].getDefaultConfiguration().getBounds();
int x = (int) rect.getMaxX() - frame.getWidth();
int y = (int) rect.getMaxY() - frame.getHeight();
frame.setLocation(x, y);
frame.setVisible(true);
}
}
}
Here is how it looks on Monitor 1
Here is how it looks on Monitor 2
If you move it up, you can see the text.
How does one ensure the Frame sits above the Task Bar each time?


