0

I have a JFrame. I use setBounds() for determine position and size, but when I use frame.setLayout( new FlowLayout() ) all components are cluttered.

What is the solution?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user3478624
  • 23
  • 1
  • 12
  • Swing GUIs might have to work on different platforms, using different PLAFs, on different screen sizes and resolutions with different default settings for font size. As such, they are not conducive to exact placement of components. Instead use layout managers, or [combinations of layout managers](http://stackoverflow.com/a/5630271/418556) as well as [layout padding and borders](http://stackoverflow.com/q/17874717/418556) for white space. – Andrew Thompson Aug 12 '14 at 07:46
  • *"`frame.setLayout( new FlowLayout() )` all components are **cluttered.**"* Needs some white space as alluded to above. Try instead `frame.setLayout( new FlowLayout(align, hgap, vgap) )`.. – Andrew Thompson Aug 12 '14 at 07:49

1 Answers1

1

1) setBounds() is bad practice with null LayoutManager(setLayout(null)).

2) When you use FlowLayout, it calculates positions and sizes of components.

So, you can't mixing 2 approaches. Examine how to use LayoutManager.

alex2410
  • 10,904
  • 3
  • 25
  • 41
  • ok,but how can determine size and position of components with FlowLayout?// frame.setLayout( new FlowLayout() ); – user3478624 Aug 12 '14 at 07:31
  • [`FlowLayout`](http://docs.oracle.com/javase/tutorial/uiswing/layout/flow.html) place components one by one in row. Seems you need to use another `BorderLayout` or `GridBagLayout`. – alex2410 Aug 12 '14 at 07:33