In the future, a proper SSCCE should include the main() method and the import statements so we don't need to do any extra work to test your code.
//lab.setHorizontalAlignment(SwingConstants.CENTER);
lab.setAlignmentX(JLabel.CENTER_ALIGNMENT);
Horizontal alignment is for the text within the bounds of the label.
AlignmentX is for the component alignment within the parent container.