Reputation: 4180
I need to have a undecorated JFrame(setUndecorated(true)) which need to be shown fullscreen, without overlapping with the taskbar.
I have tried the below solutions.
Calling setExtendedState(MAXIMIZED_BOTH).
Tried the below solution as stated in Does JFrame.setExtendedState(MAXIMIZED_BOTH) work with undecorated frames?
GraphicsConfiguration config = aFrame.getGraphicsConfiguration();
Rectangle usableBounds = SunGraphicsEnvironment.getUsableBounds(config.getDevice());
aFrame.setBounds(0, 0, usableBounds.width, usableBounds.height);
Any help would be greatly appreciated.
I thought of a design. But not sure about its feasibility. I can use the setBounds(). But then I need my frame to be notified when the task bar is adjusted or repositioned. Is there a way?
Upvotes: 4
Views: 5311
Reputation: 4180
Able to able to fix the above issue with the below code,
Rectangle usableBounds = SunGraphicsEnvironment.getUsableBounds(config.getDevice());
setMaximizedBounds(usableBounds);
setExtendedState(MAXIMIZED_BOTH);
So by getUsableBounds
I am able to get the bounds leaving the taskbar. And hence I am using setExtendedState(MAXIMIZED_BOTH)
the window is getting updated automatically when I re-size/re-position the taskbar. :-)
Upvotes: 6
Reputation: 5712
final Point x = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
Have a separate thread to check whether taskbar get changed. If so update size
new Thread(new Runnable() {
@Override
public void run() {
if (x.equals(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint())) {
Rectangle r = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
setSize(r.getSize());
}
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
}).start();
Upvotes: 0