Java tutorial
//package com.java2s; import java.awt.Dimension; import java.awt.Font; import javax.swing.JLabel; public class Main { public static JLabel getLabel(String text, int w, int h, int horizontalAlignment) { JLabel label = new JLabel(text, horizontalAlignment); label.setPreferredSize(getLabelDimension(w, h)); label.setMinimumSize(getLabelDimension(w, h)); label.setFont(getFont()); return label; } public static Dimension getLabelDimension(int w, int h) { return new Dimension(w, h); } public static Font getFont() { return new Font("Arial", Font.PLAIN, 10); } }