more accurate behavior of the search field box

dbus-notify
Zlatin Balevsky 2022-06-07 05:58:21 +01:00
parent b5eb48624f
commit 5307b08962
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 13 additions and 1 deletions

View File

@ -7,6 +7,8 @@ import javax.swing.SwingUtilities
import javax.swing.event.DocumentEvent import javax.swing.event.DocumentEvent
import javax.swing.event.DocumentListener import javax.swing.event.DocumentListener
import javax.swing.plaf.basic.BasicComboBoxEditor import javax.swing.plaf.basic.BasicComboBoxEditor
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
import java.awt.event.MouseAdapter import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent import java.awt.event.MouseEvent
@ -67,6 +69,17 @@ class SearchFieldEditor extends BasicComboBoxEditor {
showPopupMenu(e) showPopupMenu(e)
} }
}) })
editor.addKeyListener(new KeyAdapter() {
@Override
void keyPressed(KeyEvent e) {
if (e.getKeyCode() != KeyEvent.VK_ENTER)
return
if (model.getSelectedItem() != null) {
editor.setText((String)model.getSelectedItem())
}
}
})
} }
private void showPopupMenu(MouseEvent event) { private void showPopupMenu(MouseEvent event) {

View File

@ -61,7 +61,6 @@ class SearchFieldModel extends AbstractListModel implements MutableComboBoxModel
if ((selectedObject != null && !selectedObject.equals( anObject )) || if ((selectedObject != null && !selectedObject.equals( anObject )) ||
selectedObject == null && anObject != null) { selectedObject == null && anObject != null) {
selectedObject = anObject; selectedObject = anObject;
fireContentsChanged(this, -1, -1);
} }
} }