TextField クラス
- [内容]
- 1 行だけの文章を表示,編集するためのクラスです.カットアンドペースト機能を使用して,この領域に他の文章を貼り付けたり,または,この領域の文章をコピーしたりすることも可能です.
- [コンストラクタ]
- public TextField()
- public TextField(int columns)
- public TextField(String text)
- public TextField(String text, int columns)
- TextField オブジェクトを生成する
- [主なメソッド]
- public void addActionListener(ActionListener l)
- ActionListener を付け加える(改行キーが押されたときの処理)
- public void addTextListener(TextListener l)(文字が変更されたときの処理) ( TextComponent から継承)
- TextListener を付け加える
- public int getCaretPosition() ( TextComponent から継承)
- 挿入位置(カーソルの現在位置)を返す
- public int getColumns()
- 現在の列数を返す
- public Graphics getGraphics() ( Component から継承)
- このコンポーネントのグラフィックスコンテキストを作成する.コンポーネントが現在表示可能でない場合は,null を返す.(参照: TextArea クラス)
- public String getSelectedText() ( TextComponent から継承)
- 選択されたテキストを返す
- public int getSelectionEnd() ( TextComponent から継承)
- 選択されたテキストの終了位置(最後の文字の次)を返す
- public int getSelectionStart() ( TextComponent から継承)
- 選択されたテキストの開始位置を返す
- public String getText() ( TextComponent から継承)
- テキストの内容を返す
- public void paint(Graphics g) ( Component から継承)
- 描画
- public void paintAll(Graphics g) ( Component から継承)
- このコンポーネントおよびそのすべてのサブコンポーネントを描画
- public void removeActionListener ( ActionListener l )
- ActionListener を取り除く
- public void removeTextListener ( TextListener l ) ( TextComponent から継承)
- TextListener を取り除く
- public void repaint() ( Component から継承)
- public void repaint(int x, int y, int width, int height) ( Component から継承)
- public void repaint(long tm) ( Component から継承)
- public void repaint(long tm, int x, int y, int width, int height) ( Component から継承)
- 指定された矩形領域を,tm ミリ秒以内に再描画する
- public void select(int selectionStart, int selectionEnd) ( TextComponent から継承)
- テキストの指定された領域を選択する( selectionEnd の位置は選択されない)
- public void selectAll() ( TextComponent から継承)
- すべてのテキストを選択する
- public void setBackground(Color c) ( TextComponent から継承)
- バックグラウンドカラーを設定する
- public void setCaretPosition(int position) ( TextComponent から継承)
- カーソルの位置を設定する
- public void setColumns(int columns)
- 列数を設定する
- public void setEchoChar(char c)
- エコー文字を設定する.エコー文字が 0 の時は,入力された文字がすべてそのまま表示される.パスワードを入力するような場合は,0 以外を設定しておくべきである.
- public void setEditable(boolean b) ( TextComponent から継承)
- 編集可能か否かを設定する
- public void setEnabled(boolean b) ( Component から継承)
- コンポーネントを enable,または,disable にする.disable にするとイベントを受け付けなくなる.
- public void setFont(Font f) ( Component から継承)
- フォントを設定する
- public void setForeground(Color c) ( Component から継承)
- フォアグラウンドカラーを設定する
- public void setText(String t)
- 指定された文字列を設定する
- public void setVisible(boolean b) ( Component から継承)
- コンポーネントを表示,非表示にする
- [使用例]
- プログラム例は,TextArea クラス,及び,TextField クラスの各メソッド等の使用例です.上から 2 番目の TextField では,エコー文字として '*' が設定されていますので,入力された文字がすべて * に代わるはずです.また,テキストエリアの文字列の初期設定は,「 Text Area 」です.それ以外の文字は,様々なメソッドによって生成されたものです.

- プログラム例は,TextArea クラス,及び,TextField クラスに対するイベント処理の例です.上のテキストフィールドに文字を入力し改行キーを押すと,その内容がテキストエリアに表示されます( ActionListener の利用).また,テキストエリアの内容を変更すると,2 番目のテキストフィールドにメッセージが表示されます( TextListener の利用).

- [参照]
- TextArea, JTextField, JPasswordField, ActionListener, ActionEvent, TextListener, TextEvent