[java] Task bar height in java
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
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.
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.
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.
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.
Quote:Original post by capn_midnightQuote: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 ZaxxQuote:Original post by capn_midnightQuote: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
Popular Topics
Advertisement