-1

I've created a custom JPanel, added JLabel and type some text in it, and made the JLabel as small as possible, so that the text fits it. I'm using the absolute layout.

However, when I use it in my JFrame, the text no longer fits the JLabel, even though it did in the designer. Is there any particular reason for this? Or is it a bug?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user5539357
  • 1,024
  • 1
  • 9
  • 19
  • Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson May 16 '16 at 10:42

1 Answers1

1

Don't use the absolute flow layout. That's why you get this problem - let a real layout manager handle the size of your component instead of setting defaults.

There are some good tutorials around.