Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How can find the task bar height of the PC desktop

843806Apr 2 2008 — edited Apr 2 2008
Hi all,

I want to find the height of the task bar of the PC desktop screen. It can be on any OS such as Windows, Linux, Mac..

I have done something this. Create a JFrame and maximize it by make setVisible to true. Then get the height of it and dispose it. At the same time find the screen height using Toolkit. Then take the difference of it.

My question is, even in the sudden time that JFrame is appear and dispose, it blink on the screen. I want to avoid it. Anybody can give me a solution for it.

Here is my code.
        int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
	final JFrame tempFrame = new JFrame();
	tempFrame.addFocusListener(new FocusListener() {

	    public void focusGained(FocusEvent e) {
		tempFrame.dispose();
	    }

	    public void focusLost(FocusEvent e) {
	    }
	});
	tempFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
	tempFrame.setVisible(true);
	int frameHeight = tempFrame.getHeight();
	int taskbarHeight = screenHeight - frameHeight;
        tempFrame.dispose();
Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 30 2008
Added on Apr 2 2008
2 comments
195 views