JCheckBox checkBox1 = new JCheckBox("Checkbox 1"); checkBox1.setHorizontalAlignment(SwingConstants.LEFT);
JCheckBox checkBox2 = new JCheckBox("Checkbox 2"); checkBox2.setHorizontalAlignment(SwingConstants.CENTER);In this example, the horizontal alignment of the checkbox label "Checkbox 2" is set to center using the setHorizontalAlignment method. The JCheckBox class is part of the javax.swing package library.