Reputation: 777
I need to add a simple gap/space/margin whatever to have space between these two buttons. Unfortunately I can't make it work. Could anyone give me some advice?
It's based on BorderLayout
, the buttons are in a JToolBar
Upvotes: 3
Views: 5624
Reputation: 42176
What layout is on the JPanel
that contains those buttons? You could use a BoxLayout
and add Box.createHorizontalStrut()
to it.
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
buttonPanel.add(playButton);
buttonPanel.add(previousButton);
buttonPanel.add(Box.createHorizontalStrut(25));
buttonPanel.add(stopButton);
buttonPanel.add(Box.createHorizontalGlue());
Upvotes: 5
Reputation: 168815
See JToolBar.addSeparator()
which:
Appends a separator of default size to the end of the tool bar. The default size is determined by the current look and feel.
Or JToolBar.addSeparator(Dimension)
which:
Appends a separator of a specified size to the end of the tool bar.
Upvotes: 3