Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add gap between two buttons in JToolBar?

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

like image 350
user2061853 Avatar asked Dec 13 '25 12:12

user2061853


1 Answers

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());
like image 63
Kevin Workman Avatar answered Dec 15 '25 01:12

Kevin Workman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!