I have a Java frame with buttons an开发者_如何学编程d 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?
Have a look at Java Layouts.
They are responsible for placing and resizing the components within your container.
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.
精彩评论