使用BorderLayout将JButton放在屏幕的中心 [英] Put a JButton in the center of the screen with BorderLayout

查看:251
本文介绍了使用BorderLayout将JButton放在屏幕的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 BorderLayout() JButton 添加到JFrame的中心?我尝试使用 BorderLayout.CENTER ,但它取代了屏幕的中心,它给出了屏幕的顶部中心。或者我必须使用另一个布局管理器吗?

解决方案

放一个 JPanel CENTER 中,将布局设置为 GridBagLayout BoxLayout 如。




How to add a JButton into the center of a JFrame with BorderLayout()? I tried using BorderLayout.CENTER, but instead of the center of the screen, it gave the top-center of the screen. Or do I have to use another layout manager?

解决方案

Put a JPanel in the CENTER and set the layout to GridBagLayout or BoxLayout as seen in this answer to Set component at center of the page.

The GridBagLayout is used to center a label containing the yellow/red gradient image seen in the Nested Layout Example.

这篇关于使用BorderLayout将JButton放在屏幕的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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