Java tutorial
//package com.java2s; import java.awt.GridLayout; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; public class Main { /** * Creates a <code>JPanel</code> containing the given text placed in the * center as the only component. * @param text - the text to put on the panel * @return a JPanel containing only the given text */ public static JPanel makeTextPanel(String text) { JPanel panel = new JPanel(false); JLabel filler = new JLabel(text); filler.setHorizontalAlignment(SwingConstants.CENTER); panel.setLayout(new GridLayout(1, 1)); panel.add(filler); return panel; } }