Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search in combo for text with spaces is broken #691

Closed
Chrriis opened this issue Jun 14, 2023 · 6 comments
Closed

Search in combo for text with spaces is broken #691

Chrriis opened this issue Jun 14, 2023 · 6 comments
Milestone

Comments

@Chrriis
Copy link
Contributor

Chrriis commented Jun 14, 2023

When a combo has the focus (with or without the popup showing), typing text moves the selection to the item matching what is being typed. Unfortunately with FlatLaf this does not work when the item has a space, because hitting space shows or hides the popup.

Searching with keyboard items with a space works with the Windows look and feel.

Here is a simple test case showing the issue:
ComboBoxTest.zip

Just launch, and try to select with the keyboard, for example, "d z":
image

@Chrriis
Copy link
Contributor Author

Chrriis commented Jun 23, 2023

The fix for the issue is simply to remove that line:

@DevCharly
Copy link
Collaborator

This is actually a bug in Swing.

Metal, Nimbus and Aqua L&F have the same problem because they also use the SPACE key to show the popup.

Removing the SPACE key mapping would fix this issue, but then it is no longer possible to show the popup using the Space key. Not sure how important that is...

In native macOS apps, the Space key shows the combobox popup.
Also WinUI apps (Windows 10/11) show the combobox popup when pressing the Space key.
But Win32 apps do not...

I'll check whether it is possible to fix this without removing the SPACE key mapping...

If not, then we either

  • loose the "Space key shows popup" functionality
  • or we live with this bug (and hope that it is fixed in Swing)

@Chrriis
Copy link
Contributor Author

Chrriis commented Jul 1, 2023

On Windows look and feel, "down" moves to the next item, "alt+down" shows the popup.

This search in combo boxes with spaces was reported by some users who had long list of things (people with firstname lastname, some objects with the same first keyword, etc.) and were complaining about the regression with the move to FlatLaf.
I had no choice but to patch the FlatLaf library so I cannot use the standard release anymore...

Do you know if there is an alternative way to remove that mapping without patching the library?

@DevCharly
Copy link
Collaborator

Do you know if there is an alternative way to remove that mapping without patching the library?

Sure:

UIManager.setLookAndFeel(new FlatLightLaf());

// remove Space key mapping from shared ComboBox input map, which is used for all combo boxes
InputMap inputMap = (InputMap) UIManager.get( "ComboBox.ancestorInputMap" );
if( inputMap != null )
    inputMap.remove( KeyStroke.getKeyStroke( "SPACE" ) );

@Chrriis
Copy link
Contributor Author

Chrriis commented Jul 12, 2023

Thanks for the sample code!

I tried on a combo box in Windows 10 settings and the popup is shown when pressing space only if not currently searching for an item:

  • "<space>": opens popup.
  • "John<space>": does not open the popup.

I wonder if there is a way in Swing to block the keystroke action if currently in search mode.

For the time being, I removed the space key stroke using the code you suggested.

@DevCharly
Copy link
Collaborator

fixed in latest 3.2-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

@DevCharly DevCharly added this to the 3.2 milestone Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants