【发布时间】:2012-04-19 05:06:49
【问题描述】:
原始顶部标签方向设置:
http://dl.dropbox.com/u/3238736/screenshots/Screenshot-PasswordStore-1.png
有问题的右标签方向设置:
从上面的 GUI 中,我的 JTabbedPane(右侧的蓝色选项卡)与“退出”按钮(使用 GlassPane 呈现)重叠。
注意:使用 GlassPane 将退出按钮呈现在右上角。
我想要一些 技术 建议,以移动蓝色标签为“退出”按钮留出一些间距?
创建 GlassPane 以插入退出按钮的代码如下所示:
public void addUniversalQuitBtn() {
// Thanks to http://www.java-forums.org/awt-swing/12267-how-add-jbutton-tabbed-pane-headder.html forum post regarding adding a button on glasspane.
Rectangle tabBounds = mainTabPane.getBoundsAt(0);
Container glassPane = (Container) this.getRootPane().getGlassPane();
glassPane.setVisible(true);
glassPane.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.NONE;
gbc.insets = new Insets(tabBounds.y, 0, 0, 10);
gbc.anchor = GridBagConstraints.NORTHEAST;
quitBtn.setPreferredSize(new Dimension(quitBtn.getPreferredSize().width, (int) tabBounds.getHeight() - 2));
glassPane.add(quitBtn, gbc);
}
谢谢。
【问题讨论】:
-
如果您不希望事物重叠,为什么要使用玻璃窗格?让布局管理器为您做这些事情。
-
When the tabs are set to orientate on top, the Quit button would align nicely next to the tabs but when the tabs are orientated to the right, it would overlap.我想在右上角有退出按钮。 JFrame 的关闭按钮用于将窗口图标化到系统托盘,因此应添加退出按钮以关闭应用程序。
-
哪部分解释了“玻璃窗格”的使用?
-
@thotheolh 与将 JButton 放入 Right_Top_Corner 的方式相同,可以在容器内的任何位置移动
-
按钮的位置计算有问题,您没有显示...
标签: java swing space jtabbedpane glasspane