diff options
Diffstat (limited to 'javax/swing/JTextField.java')
-rw-r--r-- | javax/swing/JTextField.java | 62 |
1 files changed, 56 insertions, 6 deletions
diff --git a/javax/swing/JTextField.java b/javax/swing/JTextField.java index 46d35929a..8872af690 100644 --- a/javax/swing/JTextField.java +++ b/javax/swing/JTextField.java @@ -37,6 +37,9 @@ exception statement from your version. */ package javax.swing; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.accessibility.AccessibleStateSet; @@ -78,6 +81,8 @@ public class JTextField extends JTextComponent private int columns; + private int align; + /** * Creates a new instance of <code>JTextField</code>. */ @@ -132,10 +137,7 @@ public class JTextField extends JTextComponent */ public JTextField(Document doc, String text, int columns) { - if (doc == null) - doc = createDefaultModel(); - - setDocument(doc); + setDocument(doc == null ? createDefaultModel() : doc); setText(text); setColumns(columns); } @@ -152,6 +154,16 @@ public class JTextField extends JTextComponent } /** + * Returns the class ID for the UI. + * + * @return "TextFieldUI"; + */ + public String getUIClassID() + { + return "TextFieldUI"; + } + + /** * Adds a new listener object to this text field. * * @param listener the listener to add @@ -175,6 +187,8 @@ public class JTextField extends JTextComponent * Returns all registered <code>ActionListener</code> objects. * * @return an array of listeners + * + * @since 1.4 */ public ActionListener[] getActionListeners() { @@ -210,10 +224,46 @@ public class JTextField extends JTextComponent throw new IllegalArgumentException(); this.columns = columns; - // FIXME: Invalidate layout. + invalidate(); + repaint(); } - public void selectAll() + public int getHorizontalAlignment() { + return align; + } + + public void setHorizontalAlignment(int newAlign) + { + int oldAlign = align; + align = newAlign; + invalidate(); + repaint(); + firePropertyChange("horizontalAlignment", oldAlign, newAlign); + } + + public void setFont(Font newFont) + { + super.setFont(newFont); + revalidate(); + } + + public Dimension getPreferredSize() + { + Dimension size; + FontMetrics fm = getFontMetrics(getFont()); + int fontHeight = fm.getMaxAscent() + fm.getMaxDescent(); + int columnWidth = fm.charWidth('m'); + + if (columns != 0) + { + size = new Dimension(columns * columnWidth + 4, fontHeight + 4); + } + else + { + size = new Dimension(10, 10); + } + + return size; } } |