|
JavaTM 2 Platform Std. Ed. v1.3 |
|||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||||
概要: 内部クラス | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--javax.swing.JComboBox
ボタンまたはテキストフィールドと、ドロップダウンリストとを結び付けるコンポーネントです。ユーザは、要求に応じて表示されるドロップダウンリストから値を選択できます。コンボボックスを編集可能にすると、コンボボックスにはユーザが値を入力できるテキストフィールドが含まれます。コンボボックス使用の例と情報については、「The Java Tutorial」の「How to Use Combo Boxes」を参照してください。
標準の Look & Feel (L&F) 表現でこのコンポーネントが使用するキーボードのキーについては、JComboBox のキーの割り当てを参照してください。
警告: このクラスの直列化されたオブジェクトは、今後の Swing リリースと互換ではなくなる予定です。現在の直列化のサポートは、短期間の運用や、同じバージョンの Swing を実行するアプリケーション間の RMI に適しています。今後の Swing リリースでは、長期間の持続性をサポートする予定です。
内部クラスの概要 | |
protected class |
JComboBox.AccessibleJComboBox
このクラスは JComboBox クラス用のユーザ補助機能のサポートを実装しています。 |
static interface |
JComboBox.KeySelectionManager
KeySelectionManager を定義するインタフェースです。 |
クラス javax.swing.JComponent から継承した内部クラス |
JComponent.AccessibleJComponent |
クラス java.awt.Container から継承した内部クラス |
Container.AccessibleAWTContainer |
クラス java.awt.Component から継承した内部クラス |
Component.AccessibleAWTComponent |
フィールドの概要 | |
protected String |
actionCommand
|
protected ComboBoxModel |
dataModel
|
protected ComboBoxEditor |
editor
|
protected boolean |
isEditable
|
protected JComboBox.KeySelectionManager |
keySelectionManager
|
protected boolean |
lightWeightPopupEnabled
|
protected int |
maximumRowCount
|
protected ListCellRenderer |
renderer
|
protected Object |
selectedItemReminder
|
クラス javax.swing.JComponent から継承したフィールド |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
クラス java.awt.Component から継承したフィールド |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
インタフェース java.awt.image.ImageObserver から継承したフィールド |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
コンストラクタの概要 | |
JComboBox()
デフォルトのデータモデルで JComboBox を生成します。 |
|
JComboBox(ComboBoxModel aModel)
項目を既存の ComboBoxModel から取る JComboBox を生成します。 |
|
JComboBox(Object[] items)
指定された配列に要素を格納する JComboBox を生成します。 |
|
JComboBox(Vector items)
指定された Vector に要素を格納する JComboBox を生成します。 |
メソッドの概要 | |
void |
actionPerformed(ActionEvent e)
このメソッドは public になっていますが、これは実装の副作用によるものです。 |
void |
addActionListener(ActionListener l)
ActionListener を追加します。 |
void |
addItem(Object anObject)
項目リストに項目を追加します。 |
void |
addItemListener(ItemListener aListener)
ItemListener を追加します。 |
void |
configureEditor(ComboBoxEditor anEditor,
Object anItem)
指定された項目でエディタを初期化します。 |
protected void |
configurePropertiesFromAction(Action a)
Action インスタンスの値に従って ActionEvent ソースのプロパティを設定するファクトリメソッドです。 |
void |
contentsChanged(ListDataEvent e)
このメソッドは public になっていますが、これは実装の副作用によるものです。 |
protected PropertyChangeListener |
createActionPropertyChangeListener(Action a)
ActionEvent ソースを Action インスタンスのプロパティの変更に従って更新するのに使う PropertyChangeListener を生成するファクトリメソッドです。 |
protected JComboBox.KeySelectionManager |
createDefaultKeySelectionManager()
デフォルトのキー選択マネージャのインスタンスを返します。 |
protected void |
fireActionEvent()
このイベントタイプの通知を配信対象として登録しているリスナーすべてに通知します。 |
protected void |
fireItemStateChanged(ItemEvent e)
このイベントタイプの通知を配信対象として登録しているリスナーすべてに通知します。 |
AccessibleContext |
getAccessibleContext()
この JComboBox に関連した AccessibleContext を返します。 |
Action |
getAction()
この ActionEvent ソースに現在設定されている Action を返します。 |
String |
getActionCommand()
アクションリスナーに送られるイベントに含まれているアクションコマンドを返します。 |
ComboBoxEditor |
getEditor()
選択された項目を JComboBox フィールドで描画および編集するために使用するエディタを返します。 |
Object |
getItemAt(int index)
指定されたインデックスのリスト項目を返します。 |
int |
getItemCount()
リスト内の項目の数を返します。 |
JComboBox.KeySelectionManager |
getKeySelectionManager()
リストのキー選択マネージャを返します。 |
int |
getMaximumRowCount()
コンボボックスがスクロールバーを使用しないで表示できる最大の項目数を返します。 |
ComboBoxModel |
getModel()
JComboBox によって現在使用されているデータモデルを返します。 |
ListCellRenderer |
getRenderer()
選択された項目を JComboBox フィールドで表示するのに使われるレンダリングを返します。 |
int |
getSelectedIndex()
指定された項目に一致する、リスト内の最初の項目を返します。 |
Object |
getSelectedItem()
現在選択されている項目を返します。 |
Object[] |
getSelectedObjects()
選択されている項目を含む配列を返します。 |
ComboBoxUI |
getUI()
このコンポーネントを描画する L&F オブジェクトを返します。 |
String |
getUIClassID()
このコンポーネントを描画する L&F クラスの名前を返します。 |
void |
hidePopup()
コンボボックスにポップアップウィンドウを閉じさせます。 |
void |
insertItemAt(Object anObject,
int index)
指定されたインデックスで項目リストに項目を挿入します。 |
protected void |
installAncestorListener()
|
void |
intervalAdded(ListDataEvent e)
項目が内部データモデルに追加されている場合に呼び出されます。 |
void |
intervalRemoved(ListDataEvent e)
値がデータモデルから削除されている場合に呼び出されます。 |
boolean |
isEditable()
JComboBox が編集可能な場合は true を返します。 |
boolean |
isFocusTraversable()
コンポーネントがフォーカスを受け取ることができる場合に true を返します。 |
boolean |
isLightWeightPopupEnabled()
軽量 (すべて Java の) ポップアップを使用している場合は true を返し、重量 (ネイティブピアの) ポップアップを使用している場合は false を返します。 |
boolean |
isPopupVisible()
ポップアップの可視性を判定します。 |
protected String |
paramString()
この JComboBox の文字列表現を返します。 |
void |
processKeyEvent(KeyEvent e)
Tab キーを探しながら、 KeyEvent を処理します。 |
void |
removeActionListener(ActionListener l)
ActionListener を削除します。 |
void |
removeAllItems()
項目リストからすべての項目を削除します。 |
void |
removeItem(Object anObject)
項目リストから項目を削除します。 |
void |
removeItemAt(int anIndex)
anIndex にある項目を削除します。 |
void |
removeItemListener(ItemListener aListener)
ItemListener を削除します。 |
protected void |
selectedItemChanged()
選択されている項目が変更されるときに呼び出されます。 |
boolean |
selectWithKeyChar(char keyChar)
指定されたキーボードの文字に対応するリスト項目を選択し、その文字に対応する項目がある場合に true を返します。 |
void |
setAction(Action a)
ActionEvent ソースに Action を設定します。 |
void |
setActionCommand(String aCommand)
アクションリスナーに送られるイベントに含まれなければならないアクションコマンドを設定します。 |
void |
setEditable(boolean aFlag)
JComboBox フィールドが編集可能かどうかを指定します。 |
void |
setEditor(ComboBoxEditor anEditor)
選択された項目を JComboBox フィールドで描画および編集するために使用されるエディタを設定します。 |
void |
setEnabled(boolean b)
項目を選択できるようにコンボボックスを有効にします。 |
void |
setKeySelectionManager(JComboBox.KeySelectionManager aManager)
キーボードの文字をリストの選択に変換するオブジェクトを設定します。 |
void |
setLightWeightPopupEnabled(boolean aFlag)
ポップアップを表示するとき、それが適当であれば JComboBox は軽量ポップアップの使用を選択します。 |
void |
setMaximumRowCount(int count)
JComboBox が表示する最大の行数を設定します。 |
void |
setModel(ComboBoxModel aModel)
JComboBox が項目のリストを取得するために使用するデータモデルを設定します。 |
void |
setPopupVisible(boolean v)
ポップアップの可視性を設定します。 |
void |
setRenderer(ListCellRenderer aRenderer)
JComboBox フィールドのリストから選択された項目を描画するレンダリングを設定します。 |
void |
setSelectedIndex(int anIndex)
インデックス anIndex にある項目を選択します。 |
void |
setSelectedItem(Object anObject)
リストのオブジェクトを指定して、選択された項目を JComboBox に設定します。 |
void |
setUI(ComboBoxUI ui)
このコンポーネントを描画する L&F オブジェクトを設定します。 |
void |
showPopup()
コンボボックスにポップアップウィンドウを表示させます。 |
void |
updateUI()
L&F が変更されたことを示す UIFactory からの通知です。 |
クラス java.lang.Object から継承したメソッド |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
フィールドの詳細 |
protected ComboBoxModel dataModel
protected ListCellRenderer renderer
protected ComboBoxEditor editor
protected int maximumRowCount
protected boolean isEditable
protected Object selectedItemReminder
protected JComboBox.KeySelectionManager keySelectionManager
protected String actionCommand
protected boolean lightWeightPopupEnabled
コンストラクタの詳細 |
public JComboBox(ComboBoxModel aModel)
ComboBoxModel
から取る JComboBox
を生成します。ComboBoxModel
が提供されるため、このコンストラクタを使って生成されたコンボボックスは、デフォルトのコンボボックスモデルを生成せず、挿入、削除、および追加の各メソッドの動作方法に強い影響を与えます。aModel
- 表示された項目のリストを提供する ComboBoxModel
DefaultComboBoxModel
public JComboBox(Object[] items)
JComboBox
を生成します。デフォルトでは、配列の最初の項目と、それにともなってデータモデルが選択されます。items
- コンボボックスに挿入するオブジェクトの配列DefaultComboBoxModel
public JComboBox(Vector items)
JComboBox
を生成します。デフォルトでは、ベクタの最初の項目と、それにともなってデータモデルが選択されます。items
- コンボボックスに挿入するベクタの配列DefaultComboBoxModel
public JComboBox()
JComboBox
を生成します。デフォルトのデータモデルは、オブジェクトの空リストです。addItem
を使って項目を追加します。デフォルトでは、データモデルの最初の項目が選択されます。DefaultComboBoxModel
メソッドの詳細 |
protected void installAncestorListener()
public void setUI(ComboBoxUI ui)
ui
- ComboBoxUI
L&F オブジェクトUIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
UIFactory
からの通知です。JComponent
内の updateUI
JComponent.updateUI()
public String getUIClassID()
JComponent
内の getUIClassID
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
public ComboBoxUI getUI()
public void setModel(ComboBoxModel aModel)
JComboBox
が項目のリストを取得するために使用するデータモデルを設定します。aModel
- 表示された項目のリストを提供する ComboBoxModel
public ComboBoxModel getModel()
JComboBox
によって現在使用されているデータモデルを返します。ComboBoxModel
public void setLightWeightPopupEnabled(boolean aFlag)
JComboBox
は軽量ポップアップの使用を選択します。このメソッドでは、この機能を無効にできます。アプリケーションが軽量コンポーネントと重量コンポーネントを混合する場合は、この機能を無効にしなければなりません。public boolean isLightWeightPopupEnabled()
public void setEditable(boolean aFlag)
JComboBox
フィールドが編集可能かどうかを指定します。編集可能な JComboBox
では、ユーザはフィールドに入力するか、またはフィールドを初期化するためにリストから項目を選択でき、そのあとにその項目を編集できます (編集はフィールドだけに影響し、リスト項目には影響しない)。編集が不可能な JComboBox
は選択された項目をフィールドに表示しますが、その選択は編集できません。aFlag
- boolean 値。true はフィールドが編集可能であることを示すpublic boolean isEditable()
JComboBox
が編集可能な場合は true を返します。デフォルトでは、コンボボックスは編集不可です。JComboBox
が編集可能な場合は true、そうでない場合は falsepublic void setMaximumRowCount(int count)
JComboBox
が表示する最大の行数を設定します。モデル内のオブジェクト数が count より大きい場合は、コンボボックスはスクロールバーを使用します。count
- スクロールバーを使用しないでリストに表示できる最大の項目数を指定する int 値public int getMaximumRowCount()
public void setRenderer(ListCellRenderer aRenderer)
デフォルトのレンダリングは、選択されたオブジェクトの toString
メソッドを呼び出して取得された文字列を表示します。ほかのレンダリングは、グラフィックイメージおよび複合項目を処理できます。
選択された項目を表示するには、リストオブジェクトおよびインデックス -1 を渡して aRenderer.getListCellRendererComponent
を呼び出します。
aRenderer
- 選択された項目を表示する ListCellRenderer
setEditor(javax.swing.ComboBoxEditor)
public ListCellRenderer getRenderer()
JComboBox
フィールドで表示するのに使われるレンダリングを返します。ListCellRenderer
public void setEditor(ComboBoxEditor anEditor)
JComboBox
フィールドで描画および編集するために使用されるエディタを設定します。エディタは、受け取る JComboBox
が編集可能な場合だけ使用されます。編集できない場合は、コンボボックスはレンダリングを使用して選択された項目を描画します。anEditor
- 選択された項目を表示する ComboBoxEditor
setRenderer(javax.swing.ListCellRenderer)
public ComboBoxEditor getEditor()
JComboBox
フィールドで描画および編集するために使用するエディタを返します。ComboBoxEditor
public void setSelectedItem(Object anObject)
JComboBox
に設定します。anObject
がリストにある場合、リストは選択された anObject
を表示します。anObject
- 選択するリストオブジェクトpublic Object getSelectedItem()
public void setSelectedIndex(int anIndex)
anIndex
にある項目を選択します。anIndex
- 選択するリスト項目を指定する int 値。0 はリスト内の最初の項目を指定するIllegalArgumentException
- anIndex
が -1 より小さい場合、あるいは anIndex
がサイズに等しいかそれより大きい場合public int getSelectedIndex()
JComboBox
がリストにない項目の選択を許可する場合、その結果が常に定義されるとは限りません。項目が選択されていない場合、またはユーザがリストにない項目を指定した場合は、-1 が返されます。public void addItem(Object anObject)
JComboBox
がデフォルトのデータモデルを使用する場合だけ機能します。JComboBox
は、空のコンストラクタで生成されていて、ほかのモデルが設定されていない場合にデフォルトのデータモデルを使用します。
警告: String オブジェクトを重複して追加すると、フォーカスおよびキーボードナビゲーションの問題が発生する可能性があります。回避策として、String オブジェクトの代わりに新しいオブジェクトに追加して、toString() メソッドが定義されることを確認してください。次に例を示します。
comboBox.addItem(makeObj("Item 1")); comboBox.addItem(makeObj("Item 1")); ... private Object makeObj(final String item) { return new Object() { public String toString() { return item; } }; }
anObject
- リストに追加する Objectpublic void insertItemAt(Object anObject, int index)
JComboBox
がデフォルトのデータモデルを使用する場合だけ機能します。JComboBox
は、空のコンストラクタで生成されていて、ほかのモデルが設定されていない場合にデフォルトのデータモデルを使用します。anObject
- リストに追加する Object
index
- 項目を追加する位置を指定する int 値public void removeItem(Object anObject)
JComboBox
がデフォルトのデータモデルを使用する場合だけ機能します。JComboBox
は、空のコンストラクタで生成されていて、ほかのモデルが設定されていない場合にデフォルトのデータモデルを使用します。anObject
- 項目リストから削除するオブジェクトpublic void removeItemAt(int anIndex)
anIndex
にある項目を削除します。このメソッドは、JComboBox
がデフォルトのデータモデルを使用する場合だけ機能します。JComboBox
は、空のコンストラクタで生成されていて、ほかのモデルが設定されていない場合にデフォルトのデータモデルを使用します。anIndex
- 削除する項目のインデックスを指定する int 値。0 はリスト内の最初の項目を示すpublic void removeAllItems()
public void showPopup()
setPopupVisible(boolean)
public void hidePopup()
setPopupVisible(boolean)
public void setPopupVisible(boolean v)
public boolean isPopupVisible()
public void addItemListener(ItemListener aListener)
ItemListener
を追加します。aListener
は、選択されている項目が変更されるときにイベントを受信します。ItemSelectable
内の addItemListener
aListener
- 通知される ItemListener
public void removeItemListener(ItemListener aListener)
ItemListener
を削除します。ItemSelectable
内の removeItemListener
aListener
- 削除される ItemListener
public void addActionListener(ActionListener l)
ActionListener
を追加します。リスナーは、ユーザが選択を終了するアクションイベントを受信します。l
- 通知される ActionListener
public void removeActionListener(ActionListener l)
ActionListener
を削除します。l
- 削除される ActionListener
public void setActionCommand(String aCommand)
aCommand
- アクションリスナーに送られる「コマンド」を含む文字列。リスナーは、受信するコマンドに応じて異なる処理を実行できるpublic String getActionCommand()
public void setAction(Action a)
ActionEvent
ソースに Action
を設定します。新しい Action
は設定済みの Action
と置き換わりますが、addActionListener
で独立して追加された ActionListener
には影響しません。Action
がすでに ActionEvent
ソースにすでに登録されている ActionListener
である場合は、再登録されません。
Action
を設定すると、ActionEvent
ソースのプロパティが、Action
の値から直ちに設定され (configurePropertiesFromAction
メソッドで実行)、続いて createActionPropertyChangeListener
メソッドが作成した PropertyChangeListener
により、Action
のプロパティの変更に従って更新されます。
a
- JComboBox
の Action
、または null
Action
,
getAction()
,
configurePropertiesFromAction(javax.swing.Action)
,
createActionPropertyChangeListener(javax.swing.Action)
public Action getAction()
ActionEvent
ソースに現在設定されている Action
を返します。Action
が設定されていない場合は、null
が返されます。ActionEvent
ソースの Action
、または null
Action
,
setAction(javax.swing.Action)
protected void configurePropertiesFromAction(Action a)
Action
インスタンスの値に従って ActionEvent
ソースのプロパティを設定するファクトリメソッドです。設定されるプロパティはサブクラスによって異なります。デフォルトでは、設定されるプロパティは Enabled
および ToolTipText
です。a
- プロパティを取得する Action
、または null
Action
,
setAction(javax.swing.Action)
protected PropertyChangeListener createActionPropertyChangeListener(Action a)
ActionEvent
ソースを Action
インスタンスのプロパティの変更に従って更新するのに使う PropertyChangeListener
を生成するファクトリメソッドです。最新の状態で保持する必要のあるプロパティのセットがデフォルトプロパティ (Text、Icon、Enabled、ToolTipText) と異なる場合は、独自の PropertyChangeListener
を提供するためにサブクラスがこのメソッドをオーバーライドすることがあります。
PropertyChangeListener
は ActionEvent
ソースへの強参照を保持しないようにする必要があります。これは、ActionEvent
ソースのガベージコレクションおよびすべての包含関係の階層のコンポーネントを妨害する可能性があるからです。Action
,
setAction(javax.swing.Action)
protected void fireItemStateChanged(ItemEvent e)
e
- 対象のイベントEventListenerList
protected void fireActionEvent()
e
- 対象のイベントEventListenerList
protected void selectedItemChanged()
public Object[] getSelectedObjects()
ItemSelectable
との互換性のために実装されます。ItemSelectable
内の getSelectedObjects
Object
の配列public void actionPerformed(ActionEvent e)
ActionListener
内の actionPerformed
public void contentsChanged(ListDataEvent e)
ListDataListener
内の contentsChanged
ListDataListener
public boolean selectWithKeyChar(char keyChar)
keyChar
- char 値。通常は、ユーザが押したキーボードのキーpublic void intervalAdded(ListDataEvent e)
ListDataListener
内の intervalAdded
ListDataListener
public void intervalRemoved(ListDataEvent e)
ListDataListener
内の intervalRemoved
ListDataListener
public void setEnabled(boolean b)
JComponent
内の setEnabled
b
- boolean 値。true の場合はコンポーネントは有効になり、false の場合は無効になるpublic void configureEditor(ComboBoxEditor anEditor, Object anItem)
anEditor
- コンボボックスのフィールドにリスト項目を表示し、その編集を可能にする ComboBoxEditor
anItem
- フィールドで表示および編集を行うオブジェクトpublic void processKeyEvent(KeyEvent e)
KeyEvent
を処理します。Tab キーが見つかると、ポップアップウィンドウが閉じます。JComponent
内の processKeyEvent
e
- 押されたキーボードのキーを含む KeyEvent
public boolean isFocusTraversable()
Editor
オブジェクトがコンポーネントの代わりにフォーカスを受け取ります。JComponent
内の isFocusTraversable
public void setKeySelectionManager(JComboBox.KeySelectionManager aManager)
public JComboBox.KeySelectionManager getKeySelectionManager()
KeySelectionManager
public int getItemCount()
public Object getItemAt(int index)
index
が範囲外の場合、つまりゼロよりも小さいか、サイズ以上の場合は、null
を返します。index
- リスト位置を示す int 値。最初の項目は 0 で始まるObject
。範囲外の場合は null
protected JComboBox.KeySelectionManager createDefaultKeySelectionManager()
KeySelectionManager
setKeySelectionManager(javax.swing.JComboBox.KeySelectionManager)
protected String paramString()
JComboBox
の文字列表現を返します。このメソッドはデバッグ専用であり、返される文字列の内容および形式は実装によって異なります。返される文字列は空の場合がありますが、null
にはなりません。JComponent
内の paramString
JComboBox
の文字列表現public AccessibleContext getAccessibleContext()
Accessible
内の getAccessibleContext
JComponent
内の getAccessibleContext
|
JavaTM 2 Platform Std. Ed. v1.3 |
|||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||||
概要: 内部クラス | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |
Java、Java 2D、JDBC は、米国およびその他の国における米国 Sun Microsystems, Inc. の商標もしくは登録商標です。
Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.