LabelTextpublic class LabelText extends JPanel implements SerializableA label and text combination, inspired by
the LabelText control in Guy Eddon's ActiveX Components book
(2nd Edition, p. 203). But done more simply, without using a GUI builder
just to create a (captiveX) project and then typing 100 lines of code. |
Fields Summary |
---|
protected JLabel | theLabelThe label component | protected JTextField | theTextFieldThe label component | protected Font | myFontThe 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 void | addActionListener(java.awt.event.ActionListener l)Adds the ActionListener to receive action events from the textfield
theTextField.addActionListener(l);
| public java.lang.String | getLabel()Get the text displayed in the label
return theLabel.getText();
| public int | getLabelAlignment()Get the label's horizontal alignment
return theLabel.getHorizontalAlignment();
| public java.lang.String | getText()Get the text displayed in the text field
return theTextField.getText();
| public void | removeActionListener(java.awt.event.ActionListener l)Remove an ActionListener from the textfield.
theTextField.removeActionListener(l);
| public void | setLabel(java.lang.String text)Set the text displayed in the label
theLabel.setText(text);
| public void | setLabelAlignment(int align)Set the label's horizontal alignment
theLabel.setHorizontalAlignment(align);
| public void | setText(java.lang.String text)Set the text displayed in the text field
theTextField.setText(text);
|
|