|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
public interface ListCellRenderer
JList 内のセルをペイントする「ゴム印」として使用できるコンポーネントを識別します。たとえば、JLabel を ListCellRenderer として使用するには、次のように書きます。
class MyCellRenderer extends JLabel implements ListCellRenderer {
public MyCellRenderer() {
setOpaque(true);
}
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
setText(value.toString());
Color background;
Color foreground;
// check if this cell represents the current DnD drop location
JList.DropLocation dropLocation = list.getDropLocation();
if (dropLocation != null
&& !dropLocation.isInsert()
&& dropLocation.getIndex() == index) {
background = Color.BLUE;
foreground = Color.WHITE;
// check if this cell is selected
} else if (isSelected) {
background = Color.RED;
foreground = Color.WHITE;
// unselected, and not the DnD drop location
} else {
background = Color.WHITE;
foreground = Color.BLACK;
};
setBackground(background);
setForeground(foreground);
return this;
}
}
JList,
DefaultListCellRenderer| メソッドの概要 | |
|---|---|
Component |
getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
指定された値を表示するように設定されたコンポーネントを返します。 |
| メソッドの詳細 |
|---|
Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
paint メソッドが呼び出されて、セルを「描画」します。リストセルのサイズが固定されていないため、リストの寸法を計算する必要がある場合には、このメソッドが呼び出されて、getPreferredSize を呼び出せるコンポーネントを生成します。
list - ペイントしている JListvalue - list.getModel().getElementAt(index) によって返される値index - セルのインデックスisSelected - 指定されたセルが選択された場合は truecellHasFocus - 指定されたセルにフォーカスがある場合は true
JList,
ListSelectionModel,
ListModel
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
Copyright 2009 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Documentation Redistribution Policy も参照してください。