List クラス
- [内容]
- 縦に並んだ項目リストから,スクロールバーを使用して項目を選択するためのクラスです.
- [コンストラクタ]
- public List()
- public List(int rows)
- public List(int rows, boolean multipleMode)
- List オブジェクトを生成する.引数の意味は,以下に示すとおりである.
- rows 表示する行の数
- multipleMode 複数選択を許すか否かを入力する.デフォルトは「許さない( false )」である.
- [主なメソッド]
- public void add(String item)
- public void add(String item, int index)
- 最後(上のメソッド),または,指定された位置に項目を追加する
- public void addActionListener(ActionListener l)
- ActionListener を追加する
- public void addItemListener(ItemListener l)
- ItemListener を追加する
- public void deselect(int index)
- 指定された項目の選択を解除する
- public Graphics getGraphics() ( Component から継承)
- このコンポーネントのグラフィックスコンテキストを作成する.コンポーネントが現在表示可能でない場合は,null を返す.(参照: TextArea クラス)
- public int getItemCount()
- 項目の数を返す
- public int getSelectedIndex()
- public int[] getSelectedIndexes()
- 選択されている項目番号( 0 から始まる)を返す
- public String getSelectedItem()
- public String[] getSelectedItems()
- 選択されている項目名を返す
- public boolean isIndexSelected(int index)
- 指定された項目が選択されているか否かを返す
- public void paint(Graphics g) ( Component から継承)
- 描画
- public void paintAll(Graphics g) ( Component から継承)
- このコンポーネントおよびそのすべてのサブコンポーネントを描画
- public void remove(int position)
- public void remove(String item)
- 指定された項目を削除する
- public void removeActionListener ( ActionListener l )
- ActionListener を取り除く
- public void removeAll()
- すべての項目を削除する
- public void removeItemListener(ItemListener l)
- ItemListener を取り除く
- 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 replaceItem(String newValue, int index)
- 指定された項目を置き換える
- public void select(int index)
- 指定された項目を選択する
- public void setBackground(Color c) ( Component から継承)
- バックグラウンドカラーを設定する
- public void setEnabled(boolean b) ( Component から継承)
- コンポーネントを enable,または,disable にする.disable にするとイベントを受け付けなくなる.
- public void setFont(Font f) ( Component から継承)
- フォントを設定する
- public void setForeground(Color c) ( Component から継承)
- フォアグラウンドカラーを設定する
- public void setMultipleMode(boolean b)
- 複数選択モードを変更する
- public void setVisible(boolean b) ( Component から継承)
- コンポーネントを表示,非表示にする
- [使用例]
- プログラム例は,リストの使用例です.イベント処理を,ItemListener を用いて行っています.

- プログラム例は,上と全く同じ例ですが,イベント処理を,ActionListener を用いて行っています.ItemListener の場合とは異なり,項目をダブルクリックしないと選択されません.
- [参照]
- Choice, JList, ItemListener, ItemEvent, ActionListener, ActionEvent