JComboBox クラス
- [内容]
- 矢印をクリックすると項目の選択リストが現れるコンポーネントです(ドロップダウンリスト).AWT の Choice クラスとほぼ同じです.
- [コンストラクタ]
- public JComboBox <type>()
- public JComboBox <type> ( ComboBoxModel aModel )
- public JComboBox <type>(Object[] items)
- JComboBox オブジェクトを生成する.type では,リストに追加する項目の型を指定する.
- [主なメソッド]
- public void addActionListener ( ActionListener l )
- ActionListener を付加する
- public void addItem(Object anObject)
- メニューに項目を追加する
- public void addItemListener ( ItemListener l )
- ItemListener を付加する
- public int getItemCount()
- 項目の数を返す
- public int getSelectedIndex()
- 選択された項目番号( 0 から始まる)を返す
- public Object getSelectedItem()
- 選択された項目を返す
- public void insertItemAt ( Object anObject, int index )
- 項目を指定された位置の前に挿入する
- public void paint(Graphics g) ( JComponent から継承)
- コンポーネントを描画
- public void paintAll(Graphics g) ( Component から継承)
- このコンポーネントおよびそのすべてのサブコンポーネントを描画
- public void paintComponent(Graphics g) ( JComponent から継承)
- コンポーネントを描画
- public void paintComponents(Graphics g) ( Container から継承)
- コンテナ内の各コンポーネントを描画
- public void removeActionListener ( ActionListener l )
- ActionListener を取り除く
- public void removeAllItems()
- すべての項目を削除する
- public void removeItem(Object anObject)
- 指定された項目を削除する
- public void removeItemAt(int anIndex)
- 指定された項目を削除する
- 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(Rectangle r) ( JComponent から継承)
- public void repaint(long tm, int x, int y, int width, int height) ( JComponent から継承)
- 指定された矩形領域を,tm ミリ秒以内に再描画する
- public void setAction(Action a)
- アクションを設定する
- public void setBackground(Color c) ( JComponent から継承)
- バックグラウンドカラーを設定する
- public void setEnabled(boolean b)
- コンポーネントを enable,または,disable にする.disable にするとイベントを受け付けなくなる.
- public void setFont(Font f) ( JComponent から継承)
- フォントを設定する
- public void setForeground(Color c) ( JComponent から継承)
- フォアグラウンドカラーを設定する
- public void setSelectedIndex(int anIndex)
- 指定された項目を選択する
- public void setVisible(boolean b) ( JComponent から継承)
- コンポーネントを表示,非表示にする
- [使用例]
- プログラム例は,JComboBox クラスの各メソッド等の使用例です.イベント処理として ActionListener を使用しています.

- プログラム例は,上と同じ例に対して,イベント処理として ItemListener を使用した例です.
- [参照]
- Choice, JList, ActionListener, ActionEvent, ItemListener, ItemEvent