Java tutorial
//package com.java2s; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class Main { /** * Creates a <code>JTextField</code> with the specified text as a label * appearing before the text field. * @param label - the text to appear in front of the text field * @param length - the length in columns of the text field * @return a <code>JPanel</code> with the labeled text field as the only element */ public static JPanel createLabeledTextField(String label, int length) { JPanel labeledTextBox = new JPanel(); JLabel l = new JLabel(label); labeledTextBox.add(l); JTextField text = new JTextField(length); labeledTextBox.add(text); return labeledTextBox; } }