代码之家  ›  专栏  ›  技术社区  ›  Daniel Ryan

使用Substance LAF向标题栏添加按钮

  •  4
  • Daniel Ryan  · 技术社区  · 14 年前

    我正试图在标题栏中添加一个按钮。好像没有 以显示和某些原因隐藏标题词。

    在我的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);
        }
    }
    
    1 回复  |  直到 14 年前
        1
  •  3
  •   Daniel Ryan    14 年前

    找到了答案。标题栏没有布局,因此您需要为添加的内容添加边界,如下所示:

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

    现在你会得到一个图标后面和标题之前的漂亮按钮:)

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