开发者

Resize buttons dynamically

开发者 https://www.devze.com 2022-12-20 06:15 出处:网络
I have a Java frame with buttons an开发者_如何学编程d I have defined it using setLayout(null).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消