Question

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);
    }
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top