FileDocCategorySizeDatePackage
LabelText.javaAPI DocExample2780Sun Mar 07 19:06:24 GMT 2004com.darwinsys.swingui

LabelText

public class LabelText extends JPanel implements Serializable
A label and text combination, inspired by the LabelText control in Guy Eddon's ActiveX Components book (2nd Edition, page 203). But done more simply.
author
Ian Darwin, http://www.darwinsys.com/
version
$Id: LabelText.java,v 1.11 2004/03/08 01:06:23 ian Exp $

Fields Summary
protected JLabel
theLabel
The label component
protected JTextField
theTextField
The text field component
protected Font
myFont
The font to use
Constructors Summary
public LabelText()
Construct the object with no initial values. To be usable as a JavaBean there MUST be a no-argument constructor.

		this("(LabelText)",  12);
	
public LabelText(String label)
Construct the object with the label and a default textfield size

		this(label, 12);
	
public LabelText(String label, int numChars)
Construct the object with given label and textfield size

		super();
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		theLabel = new JLabel(label);
		add(theLabel);
		theTextField = new JTextField(numChars);
		add(theTextField);
		//if (myFont != null) {
		//	// See setFont() below!
		//	theLabel.setFont(myFont);
		//	theTextField.setFont(myFont);
		//}
	
Methods Summary
public voidaddActionListener(java.awt.event.ActionListener l)
Adds the ActionListener to receive action events from the textfield

		theTextField.addActionListener(l);
	
public java.lang.StringgetLabel()
Get the text displayed in the label

		return theLabel.getText();
	
public intgetLabelAlignment()
Get the label's horizontal alignment

		return theLabel.getHorizontalAlignment();
	
public java.lang.StringgetText()
Get the text displayed in the text field

		return theTextField.getText();
	
public voidremoveActionListener(java.awt.event.ActionListener l)
Remove an ActionListener from the textfield.

		theTextField.removeActionListener(l);
	
public voidsetLabel(java.lang.String text)
Set the text displayed in the label

		theLabel.setText(text);
	
public voidsetLabelAlignment(int align)
Set the label's horizontal alignment

		theLabel.setHorizontalAlignment(align);
	
public voidsetText(java.lang.String text)
Set the text displayed in the text field

		theTextField.setText(text);