All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.JTextField

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----com.sun.java.swing.JComponent
                           |
                           +----com.sun.java.swing.text.JTextComponent
                                   |
                                   +----com.sun.java.swing.JTextField

public class JTextField
extends JTextComponent
JTextField is a lightweight component that allows the editing of a single line of text. It is intended to be source-compatible with java.awt.TextField where it is reasonable to do so.


Variable Index

 o notifyAction
Name of the action to send notification that the contents of the field have been accepted.

Constructor Index

 o JTextField()
Constructs a new TextField.
 o JTextField(Document, String, int)
Constructs a new JTextField that uses the given text storage model and the given number of columns.
 o JTextField(int)
Constructs a new empty TextField with the specified number of columns.
 o JTextField(String)
Constructs a new TextField initialized with the specified text.
 o JTextField(String, int)
Constructs a new TextField initialized with the specified text and columns.

Method Index

 o addActionListener(ActionListener)
Adds the specified action listener to receive action events from this textfield.
 o addMouseListener(MouseListener)
Adds a mouse listener.
 o addMouseMotionListener(MouseMotionListener)
Adds a mouse motion listener.
 o createDefaultModel()
Creates the default implementation of the model to be used at construction if one isn't explicitly given.
 o createMouseListener()
Creates a mouse listener that listens to mouse events, shifting the event's x,y positions to the scrolled view translation, and refires them to any registered mouse listeners.
 o createMouseMotionListener()
Creates a mouse motion listener that listens to mouse events, shifting the event's x,y positions to the scrolled view translation, and refires them to any registered mouse listeners.
 o fireActionPerformed()
 o getActions()
Fetches the command list for the editor.
 o getColumns()
Returns the number of columns in this TextField.
 o getColumnWidth()
Gets the column width.
 o getMinimumSize()
Returns the minimum size Dimensions needed for this TextField.
 o getPreferredSize()
Returns the preferred size Dimensions needed for this TextField.
 o getScrollOffset()
 o getUIClassID()
 o paint(Graphics)
Paint the component, translating the graphics by the scrolled amount
 o paramString()
Returns the String of parameters for this JTextField.
 o postActionEvent()
Processes action events occurring on this textfield by dispatching them to any registered ActionListener objects.
 o removeActionListener(ActionListener)
Removes the specified action listener so that it no longer receives action events from this textfield.
 o removeMouseListener(MouseListener)
Removes a mouse listener.
 o removeMouseMotionListener(MouseMotionListener)
Removes a mouse motion listener.
 o repaint(long, int, int, int, int)
Repaint the component, shifting by the scrolled amount
 o scrollRectToVisible(Rectangle)
Scrolls the field left or right.
 o setActionCommand(String)
Sets the command string used for action events.
 o setColumns(int)
Sets the number of columns in this TextField.
 o setFont(Font)
Sets the current font.
 o setScrollOffset(int)

Variables

 o notifyAction
 public static final String notifyAction
Name of the action to send notification that the contents of the field have been accepted. Typically this is bound to a carriage-return.

Constructors

 o JTextField
 public JTextField()
Constructs a new TextField.

 o JTextField
 public JTextField(String text)
Constructs a new TextField initialized with the specified text.

Parameters:
text - the text to be displayed
 o JTextField
 public JTextField(int columns)
Constructs a new empty TextField with the specified number of columns.

Parameters:
columns - the number of columns
 o JTextField
 public JTextField(String text,
                   int columns)
Constructs a new TextField initialized with the specified text and columns.

Parameters:
text - the text to be displayed
columns - the number of columns
 o JTextField
 public JTextField(Document doc,
                   String text,
                   int columns)
Constructs a new JTextField that uses the given text storage model and the given number of columns. This is the constructor through which the other constructors feed.

Parameters:
doc - the text storage to use
text - the initial string to display
columns - the number of columns to use to calculate the preferred width. If columns is set to zero, the preferred width will be whatever naturally results from the component implementation.

Methods

 o getUIClassID
 public String getUIClassID()
Returns:
"TextFieldUI"
Overrides:
getUIClassID in class JComponent
See Also:
getUIClassID, getUI
 o createDefaultModel
 protected Document createDefaultModel()
Creates the default implementation of the model to be used at construction if one isn't explicitly given.

Returns:
the default model implementation
 o getColumns
 public int getColumns()
Returns the number of columns in this TextField.

Returns:
the number of columns
 o setColumns
 public void setColumns(int columns)
Sets the number of columns in this TextField.

Parameters:
columns - the number of columns
Throws: IllegalArgumentException
if columns is less than 0
 o getColumnWidth
 protected int getColumnWidth()
Gets the column width. The meaning of what a column is can be considered a fairly weak notion for some fonts. This method is used to define the width of a column. By default this is defined to be the width of the character m for the font used. This method can be redefined to be some alternative amount

Returns:
the column width
 o getPreferredSize
 public Dimension getPreferredSize()
Returns the preferred size Dimensions needed for this TextField. If a non-zero number of columns has been set, the width is set to the columns multiplied by the column width.

Returns:
the dimensions
Overrides:
getPreferredSize in class JComponent
 o getMinimumSize
 public Dimension getMinimumSize()
Returns the minimum size Dimensions needed for this TextField. This defaults to the preferred size.

Returns:
the dimensions
Overrides:
getMinimumSize in class JComponent
 o setFont
 public void setFont(Font f)
Sets the current font. This removes cached row height and column width so the new font will be reflected.

Parameters:
f - the new font
Overrides:
setFont in class Component
 o addActionListener
 public synchronized void addActionListener(ActionListener l)
Adds the specified action listener to receive action events from this textfield.

Parameters:
l - the action listener
 o removeActionListener
 public synchronized void removeActionListener(ActionListener l)
Removes the specified action listener so that it no longer receives action events from this textfield.

Parameters:
l - the action listener
 o fireActionPerformed
 protected void fireActionPerformed()
 o setActionCommand
 public void setActionCommand(String command)
Sets the command string used for action events.

Parameters:
command - the command string
 o getActions
 public Action[] getActions()
Fetches the command list for the editor. This is the list of commands supported by the plugged-in UI augmented by the collection of commands that the editor itself supports. These are useful for binding to events, such as in a keymap.

Returns:
the command list
Overrides:
getActions in class JTextComponent
 o postActionEvent
 public void postActionEvent()
Processes action events occurring on this textfield by dispatching them to any registered ActionListener objects. This is normally called by the controller registered with textfield.

 o paramString
 protected String paramString()
Returns the String of parameters for this JTextField.

Returns:
the string of parameters
Overrides:
paramString in class Container
 o getScrollOffset
 public int getScrollOffset()
 o setScrollOffset
 public void setScrollOffset(int scrollOffset)
 o scrollRectToVisible
 public void scrollRectToVisible(Rectangle r)
Scrolls the field left or right.

Overrides:
scrollRectToVisible in class JComponent
 o repaint
 public void repaint(long tm,
                     int x,
                     int y,
                     int width,
                     int height)
Repaint the component, shifting by the scrolled amount

Overrides:
repaint in class JComponent
 o paint
 public void paint(Graphics g)
Paint the component, translating the graphics by the scrolled amount

Overrides:
paint in class JComponent
 o createMouseListener
 protected MouseListener createMouseListener()
Creates a mouse listener that listens to mouse events, shifting the event's x,y positions to the scrolled view translation, and refires them to any registered mouse listeners.

 o createMouseMotionListener
 protected MouseMotionListener createMouseMotionListener()
Creates a mouse motion listener that listens to mouse events, shifting the event's x,y positions to the scrolled view translation, and refires them to any registered mouse listeners.

 o addMouseListener
 public void addMouseListener(MouseListener l)
Adds a mouse listener.

Overrides:
addMouseListener in class Component
 o addMouseMotionListener
 public void addMouseMotionListener(MouseMotionListener l)
Adds a mouse motion listener.

Overrides:
addMouseMotionListener in class Component
 o removeMouseListener
 public void removeMouseListener(MouseListener l)
Removes a mouse listener.

Overrides:
removeMouseListener in class Component
 o removeMouseMotionListener
 public void removeMouseMotionListener(MouseMotionListener l)
Removes a mouse motion listener.

Overrides:
removeMouseMotionListener in class Component

All Packages  Class Hierarchy  This Package  Previous  Next  Index