使用 Substance LAF 将按钮添加到标题栏
我正在尝试向标题栏添加一个按钮。似乎没有 显示并因某种原因隐藏了标题词。
在我的 JFrame 中,我做:
CustomTitlePane.editTitleBar(this);
和我的标题类:
public class CustomTitlePane extends SubstanceTitlePane {
private static final long serialVersionUID = 1L;
public CustomTitlePane(JRootPane root, SubstanceRootPaneUI ui) {
super(root, ui);
}
public static void editTitleBar(JFrame frame){
JComponent title = SubstanceLookAndFeel.getTitlePaneComponent(frame);
JButton titleButton = new JButton("test");
titleButton.putClientProperty("substancelaf.internal.titlePane.extraComponentKind", ExtraComponentKind.TRAILING);
title.add(titleButton,2);
}
}
I'm trying to add a button to my title bar. It doesn't seem
to show and some reason hides the title words.
In my JFrame I do:
CustomTitlePane.editTitleBar(this);
And my title class:
public class CustomTitlePane extends SubstanceTitlePane {
private static final long serialVersionUID = 1L;
public CustomTitlePane(JRootPane root, SubstanceRootPaneUI ui) {
super(root, ui);
}
public static void editTitleBar(JFrame frame){
JComponent title = SubstanceLookAndFeel.getTitlePaneComponent(frame);
JButton titleButton = new JButton("test");
titleButton.putClientProperty("substancelaf.internal.titlePane.extraComponentKind", ExtraComponentKind.TRAILING);
title.add(titleButton,2);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了答案。标题栏没有布局,因此您需要为您添加的内容添加边界,如下所示:
现在您将在图标后面和标题之前看到一个漂亮的按钮:)
另一个选项是向标题栏添加布局管理器。
Found the answer. The title bar has no layout and therefore you need to add bounds to what ever you add like so:
Now you will get a nice button after the icon and before the title :)
The other option is to add a layout manager to the title bar.