Reputation:
I want to create an application with a custom title bar (the one with the buttons for minimize, full-screen mode, and close) which is of course, OS-specific. But I only want it on Windows currently.
I did my research and found that I can't change the default OS title bar, but I can remove it by setUndecorated(true). So I did it and found it hid the taskbar and covered the whole screen. I know I can just set a fixed size, but I realized all Windows PCs don't have the same screen size. I want it to work like the setExtendedState(JFrame.MAXIMIZED_BOTH), which doesn't work when I do it when undecorated is true...
Is there any way to keep it undecorated, not hide the taskbar, and be fullscreen at the same time? Sorry for my English, my bad :-)
Upvotes: 0
Views: 750
Reputation: 82491
If you're using JavaFX, you could use the Screen
class to get the visual bounds of the primary screen and manually move/resize the stage:
stage.initStyle(StageStyle.UNDECORATED);
Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
stage.setX(bounds.getMinX());
stage.setY(bounds.getMinY());
stage.setWidth(bounds.getWidth());
stage.setHeight(bounds.getHeight());
stage.show();
Upvotes: 2
Reputation: 324177
You can use the GraphicsEnvironment class to get the size of the screen with/without the taskbar:
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle bounds = env.getMaximumWindowBounds();
System.out.println("Screen Bounds: " + bounds );
GraphicsDevice screen = env.getDefaultScreenDevice();
GraphicsConfiguration config = screen.getDefaultConfiguration();
System.out.println("Screen Size : " + config.getBounds());
Upvotes: 2