I came across a similar problem in that I had to find out the size of ALL monitors...including for a multiple monitor setup, so this should work all the same:
Code:
private Vector monitors = new Vector();
private int numOfMon;
public void initMonitors() {
monitors.clear();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gd = ge.getScreenDevices();
for (int i = 0; i<gd.length; i++) {
GraphicsConfiguration[] gc = gd[i].getConfigurations();
for (int j = 0; j<gc.length; j++) {
if (monitors.contains(gc[j].getBounds()) == false) {
monitors.addElement(gc[j].getBounds());
}
}
}
numOfMon = monitors.size();
}
public int getNumOfMonitors() {
return numOfMon;
}
public Rectangle getSizeOfMonitor(int numOfMonitor) {
return (Rectangle)monitors.elementAt(numOfMonitor);
}
Sorry if some of the variables and stuff are missing, but the rest of it should work. I left out the code to set which monitor you want a window on...hope this helps!
Bookmarks