Since multiline buttons can be created with html text, I tried html’s line-height attribute with decimal, pixel and percentage values to change the vertical line spacing. But in vain.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LineSpacing extends JFrame {
public static final long serialVersionUID = 100L;
public LineSpacing() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(480, 240);
setLayout(new FlowLayout());
setLocationRelativeTo(null);
add(createBox("Decimal", new String[]{"0.8", "0.9", "1.1"}));
add(createBox("px", new String[]{"10px", "12px", "15px"}));
add(createBox("%", new String[]{"85%", "95%", "110%"}));
setVisible(true);
}
static public void main(String args[]) {
EventQueue.invokeLater(LineSpacing::new);
}
private Box createBox(String header, String[] values) {
Box box= Box.createVerticalBox();
JPanel p= new JPanel();
p.add(new JLabel(header, SwingConstants.CENTER));
box.add(p);
for (int i=0; i<3; i++) {
JButton b= new JButton("<html><center><span style='line-height:"+
values[i]+"'>First line<br>and the second</span></html>");
b.setPreferredSize(new Dimension(130, 40));
b.setMargin(new Insets(0,0,0,0));
box.add(b);
}
return box;
}
}