import java.awt.Color; import java.awt.FlowLayout; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; public class LabelPadding extends JFrame { public LabelPadding() { JLabel label1 = new JLabel("einfacher Text
mit Zeilenumbruch
und Padding"); EmptyBorder eBorder = new EmptyBorder(2, 10, 2, 10); // oben, rechts, unten, links LineBorder lBorder = new LineBorder(new Color(100, 100, 100)); label1.setBorder(BorderFactory.createCompoundBorder(lBorder, eBorder)); JLabel label2 = new JLabel("einfacher Text
mit Zeilenumbruch
und ohne Padding"); label2.setBorder(lBorder); this.add(label1); this.add(label2); this.setLayout(new FlowLayout()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); this.setLocationRelativeTo(null); this.setTitle("Padding mit JLabel"); this.setVisible(true); } public static void main(String[] args) { new LabelPadding(); } }