tags:

views:

36

answers:

2

I have a Java frame with buttons and I have defined it using setLayout(null).

When I expand the frame, the buttons adjust their position vertically but not horizontally.

Any advice on how to make it dynamic?

+3  A: 

Have a look at Java Layouts.

They are responsible for placing and resizing the components within your container.

Peter Lang
A: 

I would strongly recommend using a LayoutManager to control how your GUI components are laid out. The most flexible manager is probably the GridBagLayout, but it may be over-kill. Even a simple FlowLayout or BoxLayout maybe sufficient if you want to have a simple frame.

Alternatively, you can use an IDE like NetBeans to visually lay out your components (the layout is code-genned). However, knowing how basic layouts work is very useful.

Luhar