I am using JFrame
to create my GUI for a desktop application. The size of the GUI I am setting according to the resolution of the platform screen using this code.
this.setSize(this.getToolkit().getScreenSize());
The problem is that when I run the application the GUI covers all of the screen. The Windows task-bar is also hidden behind the GUI.
I want that whatever the size of the task-bar is, the task-bar should be visible in all conditions. How do I achieve that?
Since you are using a JFrame you should just call:
jFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
This takes into account the position of the taskbar.
Is your task-bar set to auto-hide?
I just ran this test code on my Windows 7 machine.
import java.awt.Frame;
import javax.swing.*;
class TestFrameSize {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame("Test Screen Size");
f.setAlwaysOnTop(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.out.println(f.getToolkit().getScreenSize());
f.setExtendedState(Frame.MAXIMIZED_BOTH);
f.setVisible(true);
System.out.println(f.getSize());
}
});
}
}
In fact, I ran it twice. Here is the output:
java.awt.Dimension[width=1920,height=1080]
java.awt.Dimension[width=1928,height=1088]
(In which the frame seems to be 8 pixels taller & wider than the available screen space - odd.)
java.awt.Dimension[width=1920,height=1080]
java.awt.Dimension[width=1928,height=1048]
40 pixels shorter, and no longer covering the task-bar.
I know this is old question but when i use jFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
or the setState
it displays it properly while displaying it for the first time. When I minimize it and again maximize it, it again covers the Task Bar. I am using Windows 7 and Java 1.7.
I found the solution here
f.setExtendedState(JFrame.MAXIMIZED_BOTH);
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
f.setMaximizedBounds(env.getMaximumWindowBounds());
f.setVisible(true);
this should do the trick.
you should be able to find the TaskbarHeight with a method
say getTaskbarHeight();
the minus that from
setFullScreen();
I found this example online
Setting screen size - taskBar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With