将组件设置在页面中央 [英] Set component at center of the page

查看:29
本文介绍了将组件设置在页面中央的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在面板中央设置一个组件(比如按钮)?

我使用 Flowlayout 以布局约束为中心,但我在面板的 top-center 位置获得按钮.

How can I set a component (say button) at center of the panel?

I used Flowlayout with layout constraint as center, but I am getting button at top-center position of the panel.

推荐答案

这可以使用 GridBagLayout 作为 AVD 提到的>1BoxLayout.有关示例代码,请参阅此答案.

This can be achieved using either GridBagLayout as mentioned by AVD1 or BoxLayout. See this answer for sample code.

我个人会为此使用 GBL,因为需要更少的代码行来布置组件&在屏幕上(在父容器中居中).

Personally I'd use GBL for this because fewer lines of code are required to get the component laid out & on-screen (centered in the parent container).

  1. 我不明白为什么这个答案没有得到更多的支持,但除此之外..

这篇关于将组件设置在页面中央的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆