我正在尝试将一个按钮添加到我的标题栏中。它似乎没有显示出来,并且某些原因隐藏了标题单词。

在我的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);
    }
}
有帮助吗?

解决方案

找到答案。标题栏没有布局,因此您需要向您添加的任何内容添加界限:

titleButton.setBounds(20, 0, 40, 20);

现在,您将在图标之后和标题之前获得一个不错的按钮:)

另一个选项是将布局管理器添加到标题栏。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top