aboutsummaryrefslogtreecommitdiff
path: root/libjava/javax/swing/JTextField.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/javax/swing/JTextField.java')
-rw-r--r--libjava/javax/swing/JTextField.java59
1 files changed, 33 insertions, 26 deletions
diff --git a/libjava/javax/swing/JTextField.java b/libjava/javax/swing/JTextField.java
index 5fe104b5093..409e2a5970f 100644
--- a/libjava/javax/swing/JTextField.java
+++ b/libjava/javax/swing/JTextField.java
@@ -1,5 +1,5 @@
/* JTextField.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,6 +35,7 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
+
package javax.swing;
import java.awt.Dimension;
@@ -49,7 +50,7 @@ import javax.accessibility.AccessibleStateSet;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import javax.swing.text.PlainDocument;
-
+import javax.swing.text.TextAction;
public class JTextField extends JTextComponent
implements SwingConstants
@@ -80,12 +81,29 @@ public class JTextField extends JTextComponent
private static final long serialVersionUID = 353853209832607592L;
+ private static final Action[] actions;
+
+ /**
+ * Name of the action that gets sent when the content of the text field
+ * gets accepted.
+ */
public static final String notifyAction = "notify-field-accept";
+ static
+ {
+ actions = new Action[1];
+ actions[0] = new TextAction(notifyAction)
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ JTextField textField = (JTextField) event.getSource();
+ textField.fireActionPerformed();
+ }
+ };
+ }
+
private int columns;
-
private int align;
-
private int scrollOffset;
/** @since 1.3 */
@@ -272,19 +290,10 @@ public class JTextField extends JTextComponent
public Dimension getPreferredSize()
{
- Dimension size;
- FontMetrics fm = getFontMetrics(getFont());
- int fontHeight = fm.getMaxAscent() + fm.getMaxDescent();
- int columnWidth = fm.charWidth('m');
-
+ Dimension size = super.getPreferredSize();
+
if (columns != 0)
- {
- size = new Dimension(columns * columnWidth + 4, fontHeight + 4);
- }
- else
- {
- size = new Dimension(10, 10);
- }
+ size.width = columns * getColumnWidth();
return size;
}
@@ -309,9 +318,15 @@ public class JTextField extends JTextComponent
scrollOffset = offset;
}
+ public Action[] getActions()
+ {
+ return TextAction.augmentList(super.getActions(), actions);
+ }
+
public void postActionEvent()
{
- ActionEvent event = new ActionEvent(this, 0, actionCommand);
+ String command = actionCommand != null ? actionCommand : getText();
+ ActionEvent event = new ActionEvent(this, 0, command);
ActionListener[] listeners = getActionListeners();
for (int index = 0; index < listeners.length; ++index)
@@ -358,17 +373,9 @@ public class JTextField extends JTextComponent
/**
* @since 1.3
*/
- public String getActionCommand()
- {
- return actionCommand;
- }
-
- /**
- * @since 1.3
- */
public void setActionCommand(String command)
{
- this.actionCommand = command;
+ actionCommand = command;
}
/**