4

JComboBoxアイテムの一部を選択不可にするにはどうすればよいですか?私はこれを試しました:

@Override
public Component getListCellRendererComponent(JList list, Object value,
    int index. boolean isSelected, boolean cellHasFocus) {

    Component comp = super.getListCellRendererComponent(list, value, index,
        isSelected, cellHasFocus);

    if (not selectable conditions) {
        comp.setEnabled(false);
        comp.setFocusable(false);
    } else {
        comp.setEnabled(true);
        comp.setFocusable(true);
    }

    return comp;
}

アイテムは灰色になりますが、ユーザーは引き続き選択できます。

4

2 に答える 2

5

「選択できない」アイテムが選択されている場合、選択されたアイテムを最後に選択されたアイテムに変更してみてください。つまり、「最後に選択したアイテム」をフィールドに保存する必要があります。

于 2010-03-04T12:25:26.383 に答える
1

私がこれをしたくなる方法は、ユーザーに有効なアイテムのみを表示することです。無効なものはすべて非表示になります。これがお役に立てば幸いです。

于 2010-03-04T12:04:21.287 に答える