문제

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);
    }
}
도움이 되었습니까?

해결책

Found the answer. The title bar has no layout and therefore you need to add bounds to what ever you add like so:

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

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top