Java JLabel set text alignment to center
import javax.swing.JFrame; import javax.swing.JLabel; public class Main extends JFrame { public Main() { super("Link JLabel with JTextField"); setDefaultCloseOperation(EXIT_ON_CLOSE); JLabel nameLabel = new JLabel("Name:"); nameLabel.setHorizontalAlignment(JLabel.CENTER); add(nameLabel);/*from ww w . jav a2 s .com*/ } public static void main(String[] args) { Main frame = new Main(); frame.pack(); frame.setVisible(true); } }