Sign in to follow this  
CRACK123

[java] Task bar height in java

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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this