[java] Task bar height in java

Started by
8 comments, last by Whackjack 18 years, 9 months ago
Hi, I am trying to write a swing application. I am doing it in windowed mode. However it looks like if I draw it at 0, 0 it seems to draw right at the top. Now this means I can't see anything plus my calculations will go wrong. How do I find the height of the taskbar so that I can subtract the taskbar height from the height and then do my calculations. Thanks
The more applications I write, more I find out how less I know
Advertisement
I remember having to use the getInsets() method for that kind of problems, but that was AWT. Maybe swing has a better solution.
I think drawing from 0,30 should sort you out. Works on mine but if some1 changes the OS settings the title bar might be bigger/smaller which will cause problems.
If you are using a JFrame to draw onto, don't. Use your JFrame and add a JPanel to it(BorderLayout.CENTER). Then draw to the JPanel. The entire JPanel will always be visible, so you can draw at 0,0 and it will be the top left visible corner.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
Quote:Original post by CaptainJester
If you are using a JFrame to draw onto, don't. Use your JFrame and add a JPanel to it(BorderLayout.CENTER). Then draw to the JPanel. The entire JPanel will always be visible, so you can draw at 0,0 and it will be the top left visible corner.


That solved lot of my problems

Thanks.
The more applications I write, more I find out how less I know
You can also just add your JPanel to your JFrame, then use the JFrame's pack() method. This will resize your frame to fit your panel.
Quote:Original post by CaptainJester
If you are using a JFrame to draw onto, don't. Use your JFrame and add a JPanel to it(BorderLayout.CENTER). Then draw to the JPanel. The entire JPanel will always be visible, so you can draw at 0,0 and it will be the top left visible corner.

A nice, quick fix.

Quote:Original post by Zaxx
You can also just add your JPanel to your JFrame, then use the JFrame's pack() method. This will resize your frame to fit your panel.

Except this will resize the window down to an unusable size unless there are controls in the panel.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Quote:Original post by chris_j_pook
I think drawing from 0,30 should sort you out. Works on mine but if some1 changes the OS settings the title bar might be bigger/smaller which will cause problems.

very, very platform dependent. On most windows systems it's actually more like 5, 24. On OSX it's 0, 20 I think, in Gnome it can be as much as 10, 30. Never, ever, ever do this.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Quote:Original post by capn_midnight
Quote:Original post by Zaxx
You can also just add your JPanel to your JFrame, then use the JFrame's pack() method. This will resize your frame to fit your panel.

Except this will resize the window down to an unusable size unless there are controls in the panel.


I'm not sure I understand this. Could you explain, please?
Quote:Original post by Zaxx
Quote:Original post by capn_midnight
Quote:Original post by Zaxx
You can also just add your JPanel to your JFrame, then use the JFrame's pack() method. This will resize your frame to fit your panel.

Except this will resize the window down to an unusable size unless there are controls in the panel.


I'm not sure I understand this. Could you explain, please?


When pack() is called, it squeezes all of the controls close together. If there aren't any controls to "pack", it instead shrinks the entire window down way too much.

This topic is closed to new replies.

Advertisement