把JButton放在右下角 [英] Put JButton in bottom right

查看:128
本文介绍了把JButton放在右下角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一个空的JPanel的右下角放一个按钮

I need to put a button in the bottom right of an otherwise empty JPanel

 +-----------------------------------+
 |                                   |
 |                                   |
 |                                   |
 |                                   |
 |                                   |
 |                                   |
 |                                   |
 |                                   |
 |                      +-----------+|
 |                      | Click Me! ||
 |                      +-----------+|
 +-----------------------------------+

我该怎么做?它应该很容易吗?我想找到正确的布局管理器,而不是使用一系列嵌套面板。

How do I do that? It should be easy right? I would like to find the correct layout manager rather than using a sequence of nested panels.

JPanel panel = new JPanel();
panel.setLayout(new SomeKindOfLayoutManagerThatDoesThis());
panel.add(new JButton("Click Me!"), SETTINGS);


推荐答案

我建议使用带有Flow Layout的Border Layout管理器。

I would suggest using the Border Layout manager with Flow Layout.

类似于:

this.setLayout(new BorderLayout());
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
JButton clickmeButton = new JButton("Click Me");
buttonPanel.add(clickmeButton);
this.add(buttonPanel,BorderLayout.SOUTH);

这篇关于把JButton放在右下角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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