Suggestions:
- Consider placing the JButton in a JPanel that is below or above the JTabbedPane so that it is always visible, and you will only need one button.
- Or if it must be in a component held in the tabs, then each will need its own unique JButton, but they can share the same Action, which is what I recommend you do: Create an inner private class that extends AbstractAction, create an instance of this inner class, pass it into each JButton via either the JButton's constructor or its
setAction(...)
method. - Your BoxLayout problem is completely unrelated to your original question and should not even be part of this discussion. Yes, a BoxLayout must be used in one container, and that same container should be passed into the BoxLayout. Likely you're adding it to the JFrame, but in reality this adds it to the JFrame's contentPane, and so for this to work, you must pass
frame.getContentPane()
into the BoxLayout's first constructor parameter:
frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.PAGE_AXIS));
This is one reason I don't like adding components or setting layouts directly on the top level window since it is nothing but misleading syntactic sugar.
I much prefer:
JPanel contentPane = (JPanel) frame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));