I'm currently creating a fullscreen Java application that will be like a kiosk application. The thing is, the application is going to be on multiple different computers with different screen sizes and resolutions, so I won't be able to place my SWING components in an absolute manner.
I'm wondering what is the best way to approach such a problem when creating that type of program. So far, I'm leaning toward using percentages relative to the screen size and positioning my components accordingly.
The problem I'm foreseeing, though, is that if I want to allocate a part of the screen to, let's say, a JLabel, using percentage values the label is going to be smaller on smaller screens and a string with more letters won't be able to be displayed fully.
The solution would then be to use FontMetrics to scale the text with the size of the Labels / Buttons / etc, but I don't know much about the FontMetrics class and all the calculations I'd have to make to make the text the right size.
Basically, what I want to know is: Am I approaching this the correct way or am I making it too complicated for myself? I'm pretty sure I could do it the way I just described, but I don't want to waste too much time on this if there's a solution that would only take a fraction of the time.
In principle, this is what the LayoutManagers are for: http://download.oracle.com/javase/6/docs/api/java/awt/LayoutManager.html
If none of the default ones suit your needs, then you will have to work out the math by hand to figure out how to optimize the placement of your components at different resolutions/aspect ratios. (Which is what it sounds like you were going to do anyway.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With