これはLAFによって制御されます。
デフォルトのロジックでは、同じキーを入力すると、リスト内の次の項目に循環します。
"22 ..."の数字は、 "2 ..."で始まる各項目を通過するため、直接移動することはできません。
しかし、「2301」や「2311」のような番号がある場合は、その番号に直接行くことができます。ここで
はBasicListUIクラスで見つかったロジックです:
public void keyTyped(KeyEvent e) {
JList src = (JList)e.getSource();
ListModel model = src.getModel();
if (model.getSize() == 0 || e.isAltDown() ||
BasicGraphicsUtils.isMenuShortcutKeyDown(e) ||
isNavigationKey(e)) {
// Nothing to select
return;
}
boolean startingFromSelection = true;
char c = e.getKeyChar();
long time = e.getWhen();
int startIndex = adjustIndex(src.getLeadSelectionIndex(), list);
if (time - lastTime < timeFactor) {
typedString += c;
if((prefix.length() == 1) && (c == prefix.charAt(0))) {
// Subsequent same key presses move the keyboard focus to the next
// object that starts with the same letter.
startIndex++;
} else {
prefix = typedString;
}
} else {
startIndex++;
typedString = "" + c;
prefix = typedString;
}
lastTime = time;
if (startIndex < 0 || startIndex >= model.getSize()) {
startingFromSelection = false;
startIndex = 0;
}
int index = src.getNextMatch(prefix, startIndex,
Position.Bias.Forward);
if (index >= 0) {
src.setSelectedIndex(index);
src.ensureIndexIsVisible(index);
} else if (startingFromSelection) { // wrap
index = src.getNextMatch(prefix, 0,
Position.Bias.Forward);
if (index >= 0) {
src.setSelectedIndex(index);
src.ensureIndexIsVisible(index);
}
}
}
は、「接頭辞」変数が設定されているコメントを注意してください。
したがって、動作を変更する場合は、カスタムUIを作成してメソッドをオーバーライドする必要があります。メソッドがプライベート変数またはメソッドを使用するかどうかはわかりません。
また、デフォルトのKeyListenerをJListから削除することもできます。次に、独自のKeyListenerを実装し、カスタム確定プレフィックスを使用してgetNextMatch(...)
を直接呼び出すことができます。
MCVEを読んで作成してください! http://stackoverflow.com/help/how-to-ask&http://stackoverflow.com/help/mcve – StackFlowed