JavaTM Platform
Standard Ed. 6

javax.swing
クラス DefaultListSelectionModel

java.lang.Object
  上位を拡張 javax.swing.DefaultListSelectionModel
すべての実装されたインタフェース:
Serializable, Cloneable, ListSelectionModel

public class DefaultListSelectionModel
extends Object
implements ListSelectionModel, Cloneable, Serializable

リスト選択のデフォルトデータモデルです。

警告: このクラスの直列化されたオブジェクトは、今後の Swing リリースと互換ではなくなる予定です。現在の直列化のサポートは、短期間の運用や、同じバージョンの Swing を実行するアプリケーション間の RMI に適しています。JDK Version 1.4 以降、すべての JavaBeans の長期間の運用サポートは、java.beans パッケージに追加されています。詳細は、XMLEncoder を参照してください。

関連項目:
ListSelectionModel

フィールドの概要
protected  boolean leadAnchorNotificationEnabled
           
protected  EventListenerList listenerList
           
 
インタフェース javax.swing.ListSelectionModel から継承されたフィールド
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)
          firstIndexlastIndex 間で選択の値が変更されたことを ListSelectionListeners に通知します。
protected  void fireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
           
 int getAnchorSelectionIndex()
          setSelectionInterval()、addSelectionInterval()、または removeSelectionInterval() の直前の呼び出しから、最初のインデックス引数を返します。
 int getLeadSelectionIndex()
          setSelectionInterval()、addSelectionInterval()、または removeSelectionInterval() の直前の呼び出しから、2 番目のインデックス引数を返します。
<T extends EventListener>
T[]
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()
          このオブジェクトのプロパティーを表示および識別する文字列を返します。
 
クラス java.lang.Object から継承されたメソッド
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

フィールドの詳細

listenerList

protected EventListenerList listenerList

leadAnchorNotificationEnabled

protected boolean leadAnchorNotificationEnabled
コンストラクタの詳細

DefaultListSelectionModel

public DefaultListSelectionModel()
メソッドの詳細

getMinSelectionIndex

public int getMinSelectionIndex()
最初に選択されたインデックスを返すか、選択範囲が空の場合に -1 を返します。

定義:
インタフェース ListSelectionModel 内の getMinSelectionIndex

getMaxSelectionIndex

public int getMaxSelectionIndex()
最後に選択されたインデックスを返すか、選択範囲が空の場合に -1 を返します。

定義:
インタフェース ListSelectionModel 内の getMaxSelectionIndex

getValueIsAdjusting

public boolean getValueIsAdjusting()
選択に一連の変更を適用中である場合に true を返します。

定義:
インタフェース ListSelectionModel 内の getValueIsAdjusting
戻り値:
選択に一連の変更を適用中である場合は true
関連項目:
ListSelectionModel.setValueIsAdjusting(boolean)

getSelectionMode

public int getSelectionMode()
現在の選択モードを返します。

定義:
インタフェース ListSelectionModel 内の getSelectionMode
戻り値:
現在の選択モード
関連項目:
ListSelectionModel.setSelectionMode(int)

setSelectionMode

public void setSelectionMode(int selectionMode)
選択モードを設定します。使用可能な選択モードは、次のリストのとおりです。

定義:
インタフェース ListSelectionModel 内の setSelectionMode
例外:
IllegalArgumentException - 許可された選択モードでない場合
関連項目:
ListSelectionModel.getSelectionMode()

isSelectedIndex

public boolean isSelectedIndex(int index)
指定のインデックスが選択されている場合に true を返します。

定義:
インタフェース ListSelectionModel 内の isSelectedIndex

isSelectionEmpty

public boolean isSelectionEmpty()
インデックスが選択されていない場合に true を返します。

定義:
インタフェース ListSelectionModel 内の isSelectionEmpty

addListSelectionListener

public void addListSelectionListener(ListSelectionListener l)
選択範囲の変更が通知されるリスナーをリストに追加します。

定義:
インタフェース ListSelectionModel 内の addListSelectionListener
パラメータ:
l - ListSelectionListener
関連項目:
ListSelectionModel.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)

removeListSelectionListener

public void removeListSelectionListener(ListSelectionListener l)
選択範囲の変更が通知されるリスナーをリストから削除します。

定義:
インタフェース ListSelectionModel 内の removeListSelectionListener
パラメータ:
l - ListSelectionListener
関連項目:
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)

getListSelectionListeners

public ListSelectionListener[] getListSelectionListeners()
この DefaultListSelectionModel に登録されているすべてのリスト選択リスナーの配列を返します。

戻り値:
このモデルのすべての ListSelectionListener。 リスト選択リスナーが現在登録されていない場合は空の配列
導入されたバージョン:
1.4
関連項目:
addListSelectionListener(javax.swing.event.ListSelectionListener), removeListSelectionListener(javax.swing.event.ListSelectionListener)

fireValueChanged

protected void fireValueChanged(boolean isAdjusting)
一連の調整が終了したことをリスナーに通知します。


fireValueChanged

protected void fireValueChanged(int firstIndex,
                                int lastIndex)
firstIndexlastIndex 間で選択の値が変更されたことを ListSelectionListeners に通知します。


fireValueChanged

protected void fireValueChanged(int firstIndex,
                                int lastIndex,
                                boolean isAdjusting)
パラメータ:
firstIndex - 範囲の先頭のインデックス
lastIndex - 範囲の最後のインデックス
isAdjusting - 一連の調整の最後の変更である場合は true
関連項目:
EventListenerList

getListeners

public <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 として登録されているすべてのオブジェクトの配列。 このモデル上の FooListener。 そのようなリスナーが追加されていない場合は 空の配列
例外:
ClassCastException - listenerTypejava.util.EventListener を実装するクラスまたはインタフェースを指定しない場合
導入されたバージョン:
1.3
関連項目:
getListSelectionListeners()

setLeadAnchorNotificationEnabled

public void setLeadAnchorNotificationEnabled(boolean flag)
leadAnchorNotificationEnabled フラグの値を設定します。

関連項目:
isLeadAnchorNotificationEnabled()

isLeadAnchorNotificationEnabled

public boolean isLeadAnchorNotificationEnabled()
leadAnchorNotificationEnabled フラグの値を返します。leadAnchorNotificationEnabled が true の場合、選択領域のすべての変更に加えて、先頭インデックスとアンカーインデックスへの変更をカバーする境界を使用して、モデルは通知イベントを生成します。フラグを false に設定すると、最後の変更後に選択または選択解除された要素のみを含むように、イベントの境界を限定できます。どの方法でも、モデルは先頭変数とアンカー変数を内部的に管理し続けます。policy.allowSystemProperty プロパティーのデフォルト値は true です。

注:先頭またはアンカーは、選択領域に変更を加えなくても変更できます。これらの変更の通知は、ビュー内で新しい先頭やアンカーを更新する必要がある場合などに重要です。したがって、デフォルト値を変更するときはよく注意してください。

戻り値:
leadAnchorNotificationEnabled フラグの値
関連項目:
setLeadAnchorNotificationEnabled(boolean)

clearSelection

public void clearSelection()
選択範囲を空のセットに変更します。これによって現在の選択範囲が変更される場合には、各 ListSelectionListener に通知します。

定義:
インタフェース ListSelectionModel 内の clearSelection
関連項目:
ListSelectionModel.addListSelectionListener(javax.swing.event.ListSelectionListener)

setSelectionInterval

public void setSelectionInterval(int index0,
                                 int index1)
選択範囲を index0 以上 index1 以下に変更します。index0index1 以下でなくてもかまいません。

SINGLE_SELECTION 選択モードでは、2 番目のインデックスだけが使用されます。

これによって現在の選択範囲が変更される場合には、各 ListSelectionListener に変更が通知されます。

どちらかのインデックスが -1 である場合、このメソッドは何も行わず、例外なしで返されます。どちらのインデックスも @code -1} でなく、一方のインデックスが -1 より小さい場合、IndexOutOfBoundsException がスローされます。

定義:
インタフェース ListSelectionModel 内の setSelectionInterval
パラメータ:
index0 - 区間の一方の端の値
index1 - 区間の他方の端の値
例外:
IndexOutOfBoundsException - 一方のインデックスが -1 より小さい場合 (かつ、どちらのインデックスも -1 でない場合)
関連項目:
addListSelectionListener(javax.swing.event.ListSelectionListener)

addSelectionInterval

public void addSelectionInterval(int index0,
                                 int index1)
選択範囲を、現在の選択範囲と index0 以上 index1 以下のインデックスの示す範囲との和集合に変更します。

SINGLE_SELECTION 選択モードでは、これは setSelectionInterval の呼び出しと同等で、2 番目のインデックスだけが使用されます。SINGLE_INTERVAL_SELECTION 選択モードでは、このメソッドは、指定された間隔が既存の選択範囲に隣接していたりオーバーラップしていたりしないかぎり setSelectionInterval と同様に動作するため、範囲を拡張する目的で使用できます。

これによって現在の選択範囲が変更される場合には、各 ListSelectionListener に変更が通知されます。ただし、index0index1 以下でなくてもかまいません。

どちらかのインデックスが -1 である場合、このメソッドは何も行わず、例外なしで返されます。どちらのインデックスも @code -1} でなく、一方のインデックスが -1 より小さい場合、IndexOutOfBoundsException がスローされます。

定義:
インタフェース ListSelectionModel 内の addSelectionInterval
パラメータ:
index0 - 区間の一方の端の値
index1 - 区間の他方の端の値
例外:
IndexOutOfBoundsException - 一方のインデックスが -1 より小さい場合 (かつ、どちらのインデックスも -1 でない場合)
関連項目:
addListSelectionListener(javax.swing.event.ListSelectionListener), setSelectionInterval(int, int)

removeSelectionInterval

public void removeSelectionInterval(int index0,
                                    int index1)
選択範囲を、現在の選択範囲と index0 以上 index1 以下のインデックスの示す範囲との差集合に変更します。index0index1 以下でなくてもかまいません。

SINGLE_INTERVAL_SELECTION 選択モードでは、削除によって 2 つのセクションが生成される場合、削除範囲が選択範囲の末尾 (値が大きいほうの端) まで拡張されます。たとえば選択範囲が 0 〜 10 である場合、ユーザーが任意の順序でインデックス 5、6 を指定すると、結果として得られる選択範囲は 0 〜 4 になります。

これによって現在の選択範囲が変更される場合には、各 ListSelectionListener に変更が通知されます。

どちらかのインデックスが -1 である場合、このメソッドは何も行わず、例外なしで返されます。どちらのインデックスも @code -1} でなく、一方のインデックスが -1 より小さい場合、IndexOutOfBoundsException がスローされます。

定義:
インタフェース ListSelectionModel 内の removeSelectionInterval
パラメータ:
index0 - 区間の一方の端の値
index1 - 区間の他方の端の値
例外:
IndexOutOfBoundsException - 一方のインデックスが -1 より小さい場合 (かつ、どちらのインデックスも -1 でない場合)
関連項目:
addListSelectionListener(javax.swing.event.ListSelectionListener)

insertIndexInterval

public void insertIndexInterval(int index,
                                int length,
                                boolean before)
index の前/後から始まる length インデックスを挿入します。インデックスの値自体が選択され、選択モードが SINGLE_SELECTION でない場合は、新しく挿入された項目をすべて選択済みとして設定し、そうでない場合は未選択のままにします。このメソッドは通常、選択モデルをデータモデル内の対応する変更に同期させるために呼び出されます。

定義:
インタフェース ListSelectionModel 内の insertIndexInterval

removeIndexInterval

public void removeIndexInterval(int index0,
                                int index1)
選択モデルから、index0 と index1 を両端として含む区間のインデックスを削除します。通常、このメソッドは、データモデル内の対応する変更に選択モデルを同期させるために呼び出されます。index0 は、ほかの場合と同様に、index1 以下である必要はありません。

定義:
インタフェース ListSelectionModel 内の removeIndexInterval

setValueIsAdjusting

public void setValueIsAdjusting(boolean isAdjusting)
選択に対する複数の変更を 1 つの変更の一部であると見なすかどうかを指定する、valueIsAdjusting プロパティーを設定します。このプロパティーの値を使って、生成された ListSelectionEventvalueIsAdjusting プロパティーを初期化できます。

たとえば、ユーザーのドラッグに応じて選択が更新される場合、このプロパティーの値は、ドラッグの開始時には true、終了時には false に設定できます。ドラッグ中、リスナーは、valueIsAdjusting プロパティーの値が true に設定されたイベントを受信します。ドラッグの終了時、変更がファイナライズされると、リスナーが受信するイベントのプロパティーの値は false になります。リスナーは、変更がファイナライズされたときにだけ更新を実行したい場合、このパターンを使用できます。

このプロパティーの値を true に設定すると、1 回の変更の一部と見なされる一連の変更がスタートします。プロパティーの値を false に戻すと、選択全体の変更 (選択があった場合) を記述する、valueIsAdjusting プロパティーの値が false に設定されたイベントが送信されます。

定義:
インタフェース ListSelectionModel 内の setValueIsAdjusting
パラメータ:
isAdjusting - プロパティーの変更後の値
関連項目:
ListSelectionModel.getValueIsAdjusting(), ListSelectionEvent.getValueIsAdjusting()

toString

public String toString()
このオブジェクトのプロパティーを表示および識別する文字列を返します。

オーバーライド:
クラス Object 内の toString
戻り値:
このオブジェクトの String 表現

clone

public Object clone()
             throws CloneNotSupportedException
この選択モデルの複製を、同じ選択状態で返します。listenerList は複製されません。

オーバーライド:
クラス Object 内の clone
戻り値:
このインスタンスの複製
例外:
CloneNotSupportedException - 選択モデルが、(a) Cloneable インタフェースを実装せず、また (b) clone メソッドを定義しない場合
関連項目:
Cloneable

getAnchorSelectionIndex

public int getAnchorSelectionIndex()
setSelectionInterval()、addSelectionInterval()、または removeSelectionInterval() の直前の呼び出しから、最初のインデックス引数を返します。直前の index0 が「アンカー」、直前の index1 が「リード」と見なされます。インタフェースによっては、これらのインデックスが特別に表示されます。 たとえば Windows95 では、リードインデックスが黄色い点線の輪郭で表示されます。

定義:
インタフェース ListSelectionModel 内の getAnchorSelectionIndex
関連項目:
ListSelectionModel.getLeadSelectionIndex(), ListSelectionModel.setSelectionInterval(int, int), ListSelectionModel.addSelectionInterval(int, int)

getLeadSelectionIndex

public int getLeadSelectionIndex()
setSelectionInterval()、addSelectionInterval()、または removeSelectionInterval() の直前の呼び出しから、2 番目のインデックス引数を返します。

定義:
インタフェース ListSelectionModel 内の getLeadSelectionIndex
関連項目:
ListSelectionModel.getAnchorSelectionIndex(), ListSelectionModel.setSelectionInterval(int, int), ListSelectionModel.addSelectionInterval(int, int)

setAnchorSelectionIndex

public void setAnchorSelectionIndex(int anchorIndex)
アンカー選択インデックスを設定して、すべての選択値を変更しないままにします。leadAnchorNotificationEnabled が true の場合、新旧のアンカーセルを対象とする通知を送信します。

定義:
インタフェース ListSelectionModel 内の setAnchorSelectionIndex
関連項目:
getAnchorSelectionIndex(), setLeadSelectionIndex(int)

moveLeadSelectionIndex

public void moveLeadSelectionIndex(int leadIndex)
先頭の選択インデックスを設定して、すべての選択値を未変更のままにします。leadAnchorNotificationEnabled が true の場合、新旧の先頭セルを対象とする通知を送信します。

パラメータ:
leadIndex - 新しい先頭の選択インデックス
導入されたバージョン:
1.5
関連項目:
setAnchorSelectionIndex(int), setLeadSelectionIndex(int), getLeadSelectionIndex()

setLeadSelectionIndex

public void setLeadSelectionIndex(int leadIndex)
先頭の選択インデックスを設定し、アンカーと新しい先頭の間の値が、すべて選択またはすべて選択解除のどちらかであることを保証します。アンカーインデックスの値を選択すると、[anchor, oldLeadIndex] 範囲内のすべての値をまずクリアしてから、[anchor, newLeadIndex] 範囲内のすべての値を選択します。 oldLeadIndex は古い leadIndex を表し、newLeadIndex は新しい leadIndex を表します。  

アンカーインデックスの値が選択されていない場合、同じことを逆に行います。つまり古い範囲の値を選択してから新しい範囲の値を選択解除します。

この変更のイベントを 1 つ生成し、すべてのリスナーに通知します。このイベント内で最小限の境界を生成するため、1 回のパスで操作を行います。 この方法では、ブロードキャストされた ListSelectionEvent 内の先頭と末尾のインデックスは、このメソッドによって実際に値が変更されたセルを参照します。この操作を 2 回のステップで処理すると、選択状態の効果は同じでも、2 つのイベントが生成されてしまいます。 さらに、あとで設定されるためだけにクリアされるセルが発生してしまい、変更対象の値に関連して操作される領域が広くなります。

このメソッドを UI クラスの mouseDragged メソッドで使うと、選択を拡張できます。

定義:
インタフェース ListSelectionModel 内の setLeadSelectionIndex
関連項目:
getLeadSelectionIndex(), setAnchorSelectionIndex(int)

JavaTM Platform
Standard Ed. 6

バグの報告と機能のリクエスト
さらに詳しい API リファレンスおよび開発者ドキュメントについては、Java SE 開発者用ドキュメントを参照してください。開発者向けの詳細な解説、概念の概要、用語の定義、バグの回避策、およびコード実例が含まれています。

Copyright 2009 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Documentation Redistribution Policy も参照してください。