鍍金池/ 教程/ Java/ Swing JTextField
Swing JRadioButton
Swing Layout布局
Swing JTextField
Swing JLabel
Swing開(kāi)發(fā)環(huán)境安裝
Swing JComponent類(lèi)
SWING ActionEvent事件類(lèi)
Swing JScrollBar
Swing教程首頁(yè)
Swing JFileChooser
SWING ContainerEvent事件處理類(lèi)
Swing AdjustmentListener接口
Swing WindowAdapter類(lèi)
SWING ComponentListener接口
Swing JMenuBar類(lèi)
Swing JPanel類(lèi)及實(shí)例
Swing
SWING AdjustmentEvent事件處理
Swing JWindow類(lèi)及實(shí)例
Swing介紹
Swing MouseMotionAdapter類(lèi)
SWING WindowEvent事件類(lèi)
Swing ItemListener接口
SWING MouseEvent事件類(lèi)
Swing JMenu類(lèi)
SWING KeyEvent事件類(lèi)
Swing MouseMotionListener接口
Swing JProgressBar
SWING AWTEvent事件類(lèi)
Swing JRadioButtonMenuItem類(lèi)及例子
Swing KeyAdapter類(lèi)
SWING ActionListener接口
Swing LayoutManager接口
SWING MouseMotionEvent事件處理
Swing Component類(lèi)
Swing Container類(lèi)
Swing CardLayout布局
Swing MouseAdapter類(lèi)
Swing JSlider
Swing KeyListener接口
Swing FocusAdapter類(lèi)
Swing JColorChooser
Swing ImageIcon
Swing JComboBox
Swing GroupLayout布局類(lèi)
Swing JOptionPane
Swing GridBagLayout布局類(lèi)
Swing JMenuItem類(lèi)
Swing MouseListener Interface
Swing事件適配器
SWING ComponentEvent處理類(lèi)
SWING PaintEvent事件類(lèi)
Swing FlowLayout布局類(lèi)
SWING Event事件類(lèi)
Swing FocusListener接口
Swing控件
Swing JButton
Swing JCheckBox
Swing SpringLayout布局類(lèi)
Swing容器
Swing事件處理
Swing事件監(jiān)聽(tīng)器
Swing Menu菜單類(lèi)
Swing JList
Swing ContainerListener接口
Swing LayoutManager2接口
Swing JFrame類(lèi)和實(shí)例
Swing JTextArea
SWING InputEvent事件類(lèi)
Swing BorderLayout布局
Swing WindowListener接口
Swing JCheckboxMenuItem類(lèi)及例子
Swing JSpinner
Swing GridLayout布局類(lèi)
Swing JPopupMenu類(lèi)及實(shí)例

Swing JTextField

JTextField類(lèi)是一個(gè)組件,它允許編輯一個(gè)單行文本。

類(lèi)聲明

以下是聲明的 javax.swing.JTextField 類(lèi):

public class JTextField
   extends JTextComponent
      implements SwingConstants

字段域

以下是javax.swing.JList類(lèi)字段域:

  • static String notifyAction -- 動(dòng)作名稱(chēng)的字段已被接受的內(nèi)容發(fā)送通知。

類(lèi)構(gòu)造函數(shù)

S.N. 構(gòu)造函數(shù) & 描述
1 JTextField() 
Constructs a new TextField.
2 JTextField(Document doc, String text, int columns) 
Constructs a new JTextField that uses the given text storage model and the given number of columns.
3 JTextField(int columns) 
Constructs a new empty TextField with the specified number of columns.
4 JTextField(String text) 
Constructs a new TextField initialized with the specified text.
5 JTextField(String text, int columns) 
Constructs a new TextField initialized with the specified text and columns.

類(lèi)方法

S.N. 方法 & 描述
1 protected void actionPropertyChanged(Action action, String propertyName) 
Updates the textfield's state in response to property changes in associated action.
2 void addActionListener(ActionListener l) 
Adds the specified action listener to receive action events from this textfield.
3 protected void configurePropertiesFromAction(Action a) 
Sets the properties on this textfield to match those in the specified Action.
4 protected PropertyChangeListener createActionPropertyChangeListener(Action a) 
Creates and returns a PropertyChangeListener that is responsible for listening for changes from the specified Action and updating the appropriate properties.
5 protected Document createDefaultModel() 
Creates the default implementation of the model to be used at construction if one isn't explicitly given.
6 protected void fireActionPerformed() 
Notifies all listeners that have registered interest for notification on this event type.
7 AccessibleContext getAccessibleContext() 
Gets the AccessibleContext associated with this JTextField.
8 Action getAction() 
Returns the currently set Action for this ActionEvent source, or null if no Action is set.
9 ActionListener[] getActionListeners() 
Returns an array of all the ActionListeners added to this JTextField with addActionListener().
10 Action[] getActions() 
Fetches the command list for the editor.
11 int getColumns() 
Returns the number of columns in this TextField.
12 protected int getColumnWidth() 
Returns the column width.
13 int getHorizontalAlignment() 
Returns the horizontal alignment of the text.
14 BoundedRangeModel getHorizontalVisibility()
Gets the visibility of the text field.
15 Dimension getPreferredSize() 
Returns the preferred size Dimensions needed for this TextField.
16 int getScrollOffset() 
Gets the scroll offset, in pixels.
17 String getUIClassID() 
Gets the class ID for a UI.
18 boolean isValidateRoot() 
Calls to revalidate that come from within the textfield itself will be handled by validating the textfield, unless the textfield is contained within a JViewport, in which case this returns false.
19 protected String paramString() 
Returns a string representation of this JTextField.
20 void postActionEvent() 
Processes action events occurring on this textfield by dispatching them to any registered ActionListener objects.
21 void removeActionListener(ActionListener l) 
Removes the specified action listener so that it no longer receives action events from this textfield.
22 void scrollRectToVisible(Rectangle r) 
Scrolls the field left or right.
23 void setAction(Action a) 
Sets the Action for the ActionEvent source.
24 void setActionCommand(String command) 
Sets the command string used for action events.
25 void setColumns(int columns) 
Sets the number of columns in this TextField, and then invalidate the layout.
26 void setDocument(Document doc) 
Associates the editor with a text document.
27 void setFont(Font f) 
Sets the current font.
28 void setHorizontalAlignment(int alignment) 
Sets the horizontal alignment of the text.
29 void setScrollOffset(int scrollOffset) 
Sets the scroll offset, in pixels.

方法繼承

這個(gè)類(lèi)從以下類(lèi)繼承的方法:

  • javax.swing.text.JTextComponent

  • javax.swing.JComponent

  • java.awt.Container

  • java.awt.Component

  • java.lang.Object

JTextField 例子

選擇使用任何編輯器創(chuàng)建以下java程序在 D:/ > SWING > com > yiibai > gui >

SwingControlDemo.java
package com.yiibai.gui;
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class SwingControlDemo {
    
   private JFrame mainFrame;
   private JLabel headerLabel;
   private JLabel statusLabel;
   private JPanel controlPanel;

   public SwingControlDemo(){
      prepareGUI();
   }

   public static void main(String[] args){
      SwingControlDemo  swingControlDemo = new SwingControlDemo();      
      swingControlDemo.showTextFieldDemo();
   }

   private void prepareGUI(){
      mainFrame = new JFrame("Java Swing Examples");
      mainFrame.setSize(400,400);
      mainFrame.setLayout(new GridLayout(3, 1));
      mainFrame.addWindowListener(new WindowAdapter() {
         public void windowClosing(上一篇:Swing LayoutManager接口下一篇:SWING AWTEvent事件類(lèi)