相对于 JFrame 移动组件
我有 4 个 JButton 设置在彼此下方。我希望当用户水平调整框架大小时它们左右移动。
例如:帧大小:400,400
ButtonLocation:300,200
现在我将框架大小调整为:600,400
ButtonLocation 应该是:500,200
知道如何实现这一点吗?
谢谢
I have 4 JButton setted underneath eachother. I want them to move right and left when the user resizes the frame horizontely.
eg: Frame size: 400,400
ButtonLocation: 300,200
Now I Resize the frame to : 600,400
ButtonLocation should be: 500,200
Any Idea how I can achieve this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用正确的布局管理器。例如 GridBagLayout,您可以在其中将每个按钮的填充和插入设置为 GridBagConstraints。
Use proper LayoutManager. E.g. GridBagLayout where you can set fill and Insets to GridBagConstraints for each button.
要将 4 个按钮放在一起,请将它们放在一列中
GridLayout
。要相对于框架的 RHS 移动,请将(带有GridLayout
的面板)放入BorderLayout
。有关更多详细信息,请参阅使用布局管理器。
To get 4 buttons underneath each other, put them in a single column
GridLayout
. To get then to move relative to the RHS of the frame, put the (panel with theGridLayout
) into theEAST
constraint of aBorderLayout
.See Using Layout Managers for more details.