Question

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

enter image description here

Was it helpful?

Solution 2

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.

OTHER TIPS

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());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top