public class DefaultListSelectionModel extends Object implements ListSelectionModel, Cloneable, Serializable
警告: このクラスの直列化されたオブジェクトは、今後のSwingリリースと互換ではなくなる予定です。 現在の直列化のサポートは、短期間の格納や、同じバージョンのSwingを実行するアプリケーション間のRMIに適しています。 1.4以降、すべてのJavaBeans™用の長期間の格納サポートがjava.beansパッケージに追加されています。 XMLEncoderを参照してください。
ListSelectionModel| 修飾子と型 | フィールド | 説明 |
|---|---|---|
protected boolean |
leadAnchorNotificationEnabled |
|
protected EventListenerList |
listenerList |
MULTIPLE_INTERVAL_SELECTION, SINGLE_INTERVAL_SELECTION, SINGLE_SELECTION| コンストラクタ | 説明 |
|---|---|
DefaultListSelectionModel() |
| 修飾子と型 | メソッド | 説明 |
|---|---|---|
void |
addListSelectionListener(ListSelectionListener l) |
選択範囲の変更が通知されるリスナーをリストに追加します。
|
void |
addSelectionInterval(int index0, int index1) |
選択範囲を、現在の選択範囲と
index0以上index1以下のインデックスの示す範囲との和集合に変更します。 |
void |
clearSelection() |
選択範囲を空のセットに変更します。
|
Object |
clone() |
この選択モデルの複製を、同じ選択状態で返します。
|
protected void |
fireValueChanged(boolean isAdjusting) |
一連の調整が終了したことをリスナーに通知します。
|
protected void |
fireValueChanged(int firstIndex, int lastIndex) |
firstIndex、lastIndex間で選択の値が変更されたことをListSelectionListenersに通知します。 |
protected void |
fireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting) |
|
int |
getAnchorSelectionIndex() |
setSelectionInterval()、addSelectionInterval()、またはremoveSelectionInterval()の直前の呼び出しから、最初のインデックス引数を返します。
|
int |
getLeadSelectionIndex() |
setSelectionInterval()、addSelectionInterval()、またはremoveSelectionInterval()の直前の呼び出しから、2番目のインデックス引数を返します。
|
<T extends EventListener> |
getListeners(Class<T> listenerType) |
このモデルに
FooListenerとして現在登録されているすべてのオブジェクトの配列を返します。 |
ListSelectionListener[] |
getListSelectionListeners() |
この
DefaultListSelectionModelに登録されたすべてのリスト選択リスナーの配列を返します。 |
int |
getMaxSelectionIndex() |
最後に選択されたインデックスを返すか、選択範囲が空の場合に -1を返します。
|
int |
getMinSelectionIndex() |
最初に選択されたインデックスを返すか、選択範囲が空の場合に -1を返します。
|
int |
getSelectionMode() |
現在の選択モードを返します。
|
boolean |
getValueIsAdjusting() |
選択に一連の変更を適用中である場合は
trueを返します。 |
void |
insertIndexInterval(int index, int length, boolean before) |
indexの前/後から始まるlengthインデックスを挿入します。
|
boolean |
isLeadAnchorNotificationEnabled() |
leadAnchorNotificationEnabledフラグの値を返します。 |
boolean |
isSelectedIndex(int index) |
指定のインデックスが選択されている場合にtrueを返します。
|
boolean |
isSelectionEmpty() |
インデックスが選択されていない場合にtrueを返します。
|
void |
moveLeadSelectionIndex(int leadIndex) |
先頭の選択インデックスを設定して、すべての選択値を未変更のままにします。
|
void |
removeIndexInterval(int index0, int index1) |
選択モデルから、index0とindex1を両端として含む区間のインデックスを削除します。
|
void |
removeListSelectionListener(ListSelectionListener l) |
選択範囲の変更が通知されるリスナーをリストから削除します。
|
void |
removeSelectionInterval(int index0, int index1) |
選択範囲を、現在の選択範囲と
index0以上index1以下のインデックスの示す範囲との差集合に変更します。 |
void |
setAnchorSelectionIndex(int anchorIndex) |
アンカー選択インデックスを設定して、すべての選択値を変更しないままにします。
|
void |
setLeadAnchorNotificationEnabled(boolean flag) |
leadAnchorNotificationEnabledフラグの値を設定します。
|
void |
setLeadSelectionIndex(int leadIndex) |
先頭の選択インデックスを設定し、アンカーと新しい先頭の間の値が、すべて選択またはすべて選択解除のどちらかであることを保証します。
|
void |
setSelectionInterval(int index0, int index1) |
選択範囲を
index0以上index1以下に変更します。 |
void |
setSelectionMode(int selectionMode) |
選択モードを設定します。
|
void |
setValueIsAdjusting(boolean isAdjusting) |
選択に対する複数の変更を1つの変更の一部であると見なすかどうかを指定する、
valueIsAdjustingプロパティを設定します。 |
String |
toString() |
このオブジェクトのプロパティを表示および識別する文字列を返します。
|
protected EventListenerList listenerList
protected boolean leadAnchorNotificationEnabled
public int getMinSelectionIndex()
getMinSelectionIndex、インタフェースListSelectionModelpublic int getMaxSelectionIndex()
getMaxSelectionIndex、インタフェースListSelectionModelpublic boolean getValueIsAdjusting()
trueを返します。getValueIsAdjusting、インタフェースListSelectionModelListSelectionModel.setValueIsAdjusting(boolean)public int getSelectionMode()
getSelectionMode、インタフェースListSelectionModelListSelectionModel.setSelectionMode(int)public void setSelectionMode(int selectionMode)
ListSelectionModel.SINGLE_SELECTION - 1回に1つのリスト・インデックスのみを選択できます。 このモードでは、setSelectionIntervalメソッドとaddSelectionIntervalメソッドは同等であり、どちらも現在の選択を、2番目の引数で表されるインデックス(「リード・インデックス」)で置き換えます。
ListSelectionModel.SINGLE_INTERVAL_SELECTION - 1回に1つの連続区間のみを選択できます。 このモードでは、addSelectionIntervalは、指定された間隔が既存の選択範囲に隣接していたりオーバーラップしていたりしないかぎりsetSelectionIntervalと同様に動作する(現在の選択を置き換える)ため、選択範囲を拡張するために使用できます。
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION - このモードでは、選択対象に制限はありません。
setSelectionMode、インタフェースListSelectionModelIllegalArgumentException - 許可された選択モードでない場合ListSelectionModel.getSelectionMode()public boolean isSelectedIndex(int index)
isSelectedIndex、インタフェースListSelectionModelpublic boolean isSelectionEmpty()
isSelectionEmpty、インタフェースListSelectionModelpublic void addListSelectionListener(ListSelectionListener l)
addListSelectionListener、インタフェースListSelectionModell - ListSelectionListenerListSelectionModel.removeListSelectionListener(javax.swing.event.ListSelectionListener), ListSelectionModel.setSelectionInterval(int, int), ListSelectionModel.addSelectionInterval(int, int), ListSelectionModel.removeSelectionInterval(int, int), ListSelectionModel.clearSelection(), ListSelectionModel.insertIndexInterval(int, int, boolean), ListSelectionModel.removeIndexInterval(int, int)public void removeListSelectionListener(ListSelectionListener l)
removeListSelectionListener、インタフェースListSelectionModell - ListSelectionListenerListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)public ListSelectionListener[] getListSelectionListeners()
DefaultListSelectionModelに登録されたすべてのリスト選択リスナーの配列を返します。ListSelectionListener。リスト選択リスナーが現在登録されていない場合は空の配列addListSelectionListener(javax.swing.event.ListSelectionListener), removeListSelectionListener(javax.swing.event.ListSelectionListener)protected void fireValueChanged(boolean isAdjusting)
protected void fireValueChanged(int firstIndex,
int lastIndex)
firstIndex、lastIndex間で選択の値が変更されたことをListSelectionListenersに通知します。protected void fireValueChanged(int firstIndex,
int lastIndex,
boolean isAdjusting)
firstIndex - 範囲の先頭のインデックスlastIndex - 範囲の最後のインデックスisAdjusting - 一連の調整の最後の変更である場合はtrueEventListenerListpublic <T extends EventListener> T[] getListeners(Class<T> listenerType)
FooListenerとして現在登録されているすべてのオブジェクトの配列を返します。 FooListenerは、addFooListenerメソッドを使用して登録されます。
FooListener.classなどのクラス・リテラルを使用してlistenerType引数を指定できます。 たとえば、このリスト選択リスナーに対するDefaultListSelectionModelインスタンスmの照会は次のコードで行います。
ListSelectionListener[] lsls = (ListSelectionListener[])(m.getListeners(ListSelectionListener.class));このようなリスナーがない場合は空の配列を返します。
listenerType - 要求されるリスナーの型。java.util.EventListenerの子孫のインタフェースを指定してくださいFooListenerとして登録されているすべてのオブジェクトの配列。またはこのようなリスナーが登録されていない場合は空の配列ClassCastException - listenerTypeで、java.util.EventListenerを実装するクラスまたはインタフェースが指定されなかった場合getListSelectionListeners()public void setLeadAnchorNotificationEnabled(boolean flag)
public boolean isLeadAnchorNotificationEnabled()
leadAnchorNotificationEnabledフラグの値を返します。 leadAnchorNotificationEnabledがtrueの場合、選択領域のすべての変更に加えて、先頭インデックスとアンカー・インデックスへの変更をカバーする境界を使用して、モデルは通知イベントを生成します。 フラグをfalseに設定すると、最後の変更後に選択または選択解除された要素のみを含むように、イベントの境界を限定できます。 どの方法でも、モデルは先頭変数とアンカー変数を内部的に管理し続けます。 デフォルトはtrueです。
ノート: 先頭またはアンカーは、選択領域に変更を加えなくても変更できます。 これらの変更の通知は、ビュー内で新しい先頭やアンカーを更新する必要がある場合などに重要です。 したがって、デフォルト値を変更するときはよく注意してください。
leadAnchorNotificationEnabledフラグの値setLeadAnchorNotificationEnabled(boolean)public void clearSelection()
public void setSelectionInterval(int index0,
int index1)
index0以上index1以下に変更します。index0はindex1以下でなくてもかまいません。
SINGLE_SELECTION選択モードでは、2番目のインデックスだけが使用されます。
これによって現在の選択範囲が変更される場合には、各ListSelectionListenerに変更が通知されます。
どちらかのインデックスが-1である場合、このメソッドは何も行わず、例外なしで返されます。 それ以外の場合、一方のインデックスが-1より小さい場合、IndexOutOfBoundsExceptionがスローされます。
setSelectionInterval、インタフェースListSelectionModelindex0 - 範囲の一方の端の値。index1 - 範囲の他方の端の値IndexOutOfBoundsException - 一方のインデックスが-1より小さい場合(かつ、どちらのインデックスも-1でない場合)addListSelectionListener(javax.swing.event.ListSelectionListener)public void addSelectionInterval(int index0,
int index1)
index0以上index1以下のインデックスの示す範囲との和集合に変更します。
SINGLE_SELECTION選択モードでは、これはsetSelectionIntervalの呼び出しと同等で、2番目のインデックスだけが使用されます。 SINGLE_INTERVAL_SELECTION選択モードでは、このメソッドは、指定された区間が既存の選択範囲に隣接していたりオーバーラップしていたりしないかぎりsetSelectionIntervalと同様に動作するため、範囲を拡張する目的で使用できます。
これによって現在の選択範囲が変更される場合には、各ListSelectionListenerに変更が通知されます。 ただし、index0はindex1以下でなくてもかまいません。
どちらかのインデックスが-1である場合、このメソッドは何も行わず、例外なしで返されます。 それ以外の場合、一方のインデックスが-1より小さい場合、IndexOutOfBoundsExceptionがスローされます。
addSelectionInterval、インタフェースListSelectionModelindex0 - 範囲の一方の端の値。index1 - 範囲の他方の端の値IndexOutOfBoundsException - 一方のインデックスが-1より小さい場合(かつ、どちらのインデックスも-1でない場合)addListSelectionListener(javax.swing.event.ListSelectionListener), setSelectionInterval(int, int)public void removeSelectionInterval(int index0,
int index1)
index0以上index1以下のインデックスの示す範囲との差集合に変更します。index0はindex1以下でなくてもかまいません。
SINGLE_INTERVAL_SELECTION選択モードでは、削除によって2つの不連続のセクションが生成される場合、削除範囲が選択範囲の末尾(値が大きいほうの端)まで拡張されます。 たとえば選択範囲が0-10である場合、ユーザーが任意の順序でインデックス5,6を指定すると、結果として得られる選択範囲は0-4になります。
これによって現在の選択範囲が変更される場合には、各ListSelectionListenerに変更が通知されます。
どちらかのインデックスが-1である場合、このメソッドは何も行わず、例外なしで返されます。 それ以外の場合、一方のインデックスが-1より小さい場合、IndexOutOfBoundsExceptionがスローされます。
removeSelectionInterval、インタフェースListSelectionModelindex0 - 範囲の一方の端の値index1 - 範囲の他方の端の値IndexOutOfBoundsException - 一方のインデックスが-1より小さい場合(かつ、どちらのインデックスも-1でない場合)addListSelectionListener(javax.swing.event.ListSelectionListener)public void insertIndexInterval(int index,
int length,
boolean before)
insertIndexInterval、インタフェースListSelectionModelpublic void removeIndexInterval(int index0,
int index1)
removeIndexInterval、インタフェースListSelectionModelpublic void setValueIsAdjusting(boolean isAdjusting)
valueIsAdjustingプロパティを設定します。 このプロパティの値を使って、生成されたListSelectionEventのvalueIsAdjustingプロパティを初期化できます。
たとえば、ユーザーのドラッグに応じて選択が更新される場合、このプロパティの値は、ドラッグの開始時にはtrue、終了時にはfalseに設定できます。 ドラッグ中、リスナーは、valueIsAdjustingプロパティの値がtrueに設定されたイベントを受信します。 ドラッグの終了時、変更がファイナライズされると、リスナーが受信するイベントのプロパティの値はfalseになります。 リスナーは、変更がファイナライズされたときにだけ更新を実行したい場合、このパターンを使用できます。
このプロパティの値をtrueに設定すると、1回の変更の一部と見なされる一連の変更がスタートします。 プロパティの値をfalseに戻すと、選択全体の変更(選択があった場合)を記述する、valueIsAdjustingプロパティの値がfalseに設定されたイベントが送信されます。
setValueIsAdjusting、インタフェースListSelectionModelisAdjusting - プロパティの新しい値ListSelectionModel.getValueIsAdjusting(), ListSelectionEvent.getValueIsAdjusting()public String toString()
public Object clone() throws CloneNotSupportedException
listenerListsは複製されません。clone、クラスObjectCloneNotSupportedException - 選択モデルが、(a) Cloneableインタフェースを実装せず、また(b) cloneメソッドを定義しない場合。Cloneablepublic int getAnchorSelectionIndex()
public int getLeadSelectionIndex()
public void setAnchorSelectionIndex(int anchorIndex)
public void moveLeadSelectionIndex(int leadIndex)
leadIndex - 新しい先頭の選択インデックスsetAnchorSelectionIndex(int), setLeadSelectionIndex(int), getLeadSelectionIndex()public void setLeadSelectionIndex(int leadIndex)
アンカー・インデックスの値が選択されていない場合は、同じことを逆に行います。つまり、古い範囲の値を選択してから新しい範囲の値を選択解除します。
この変更のイベントを1つ生成し、すべてのリスナーに通知します。 このイベント内で最小限の境界を生成するために、1回のパスで操作を行います。この方法では、ブロードキャストされたListSelectionEvent内の先頭と末尾のインデックスは、このメソッドによって実際に値が変更されたセルを参照します。 この操作を2回のステップで処理すると、選択状態の効果は同じでも、2つのイベントが生成されてしまいます。さらに、後で設定する目的でのみクリアされるセルが発生してしまい、変更対象の値に関連して操作される領域が広くなります。
このメソッドをUIクラスのmouseDraggedメソッドで使うと、選択を拡張できます。
バグまたは機能を送信
詳細なAPIリファレンスおよび開発者ドキュメントについては、Java SEのドキュメントを参照してください。 そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Documentation Redistribution Policyも参照してください。