1

I am working on a desktop application in Java which uses Swing with MIG layout for building the GUI. I have a lot of drag&drop actions which require "fixed" screen positions (the application works with plugs and sockets). Currently we support only one screen resolution Is it possible to build the GUI so that it is scaled somehow according to the screen resolution?

Thank you in advance

Heisenbug
  • 38,762
  • 28
  • 132
  • 190
  • What do you want to _scale_? Component sizes? Fonts? Geometry? – trashgod Aug 15 '12 at 10:47
  • 1
    similar to Mig internals (or UXGuide windows): use logical pixels and convert them to absolute on positioning. – kleopatra Aug 15 '12 at 10:47
  • 1
    @trashgod: I would like to scale images and screen positions, fonts and forms should stay the same (they are scrollable) I will check out logical pixels in MIG and see if they do the trick at least for correct positioning. – Dragan Ristovski Aug 21 '12 at 13:10

1 Answers1

3

You can get the screen resolution this way:

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

Set the size of your JFrame accordingly to it. (Remember to use setSize() only on Frame not on child Components with their own LayoutManager)

Heisenbug
  • 38,762
  • 28
  • 132
  • 190
  • +1 for speaking from [experience](http://stackoverflow.com/q/7229226/230513), but I'm guessing he wants to scale components, fonts, etc. – trashgod Aug 15 '12 at 10:44
  • trashgod is right, The GUI I have is made for one resolution only, position is important in this application because we use D&D for sockets and to be even more complicated there is a device picture in the background which also has to be scaled according to the resolution. This is not something trivial like determining screen resolution. Basically I would like to scale up or down the whole GUI based on the ratio between the original screen resolution and the detected resolution. – Dragan Ristovski Aug 15 '12 at 14:10
  • At the end we ended up developing two front ends, one for devices with low resolution screens and one with hi-res screens.Thank you all for your suggestions – Dragan Ristovski Jun 22 '13 at 18:22