• Advertisement
Sign in to follow this  

[java] Task bar height in java

This topic is 4609 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
I remember having to use the getInsets() method for that kind of problems, but that was AWT. Maybe swing has a better solution.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement