-1

How to write an swing application that abide to the screen resolution.

Ex: to add an component in panel , say Label label1, I need the position of the label1 to be added in percentage .

I dont want JFrame -> JScrollPane -> JComponents. This is a very bad approach.Components doesnt resize at all.

Is there any way to add components with respect to percentage in java ?

  • 1
    A JLabel has a fixed size. The layout manager should determine how much space to give to the label, not the resolution of the screen. Only components like a JScrollPane should vary with size as the screen resolution changes. Then the component added to the scrollpane will get more or less space depending on the resolution. This is how the browse you are using works. – camickr May 11 '14 at 15:16

1 Answers1

0

You can have more control with Miglayout. You can either control the label by pixels which can be calculated according to screen resolution, or by percentage of container size which will adjust with container resize.

Miglayout may require a little bit time to learn but it is well worth the effort. Check out the demo in Miglayout website, you can see the corresponding code for very complex UI. You can even right click any component and experiment with the constraints and see results immediately, this is a great way to learn Miglayout.

Miglayout white paper

Miglayout cheat sheet

dracodoc
  • 2,603
  • 1
  • 23
  • 33