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

Editable combo box editors do not behave like text fields for mouse clicks #330

Closed
Chrriis opened this issue May 20, 2021 · 3 comments
Closed
Milestone

Comments

@Chrriis
Copy link
Contributor

Chrriis commented May 20, 2021

Hi all!

I find that editable combo boxes do not feel right compared to text fields. The click on the left or right of the text does not edit the text, as indicated by the cursors:
TextFieldVsEditableComboBox

I originally noticed this problem in some custom components that recycle the combo box border, but this is also an issue with regular editable combo boxes. When you want to place your caret at the very beginning of the editable text, it is hard and frustrating because it expands the popup instead of editing the text (e.g. try to place your caret before a "I" for example).

Sample code:

public static void main(String[] args) throws Exception {
	UIManager.setLookAndFeel(new FlatLightLaf());
	JFrame frame = new JFrame();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	JPanel centerPane = new JPanel(new GridBagLayout());
	centerPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
	centerPane.add(new JTextField("Sample text field", 14), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
	JComboBox<String> combo = new JComboBox<>(new String[] {"Item 1", "Item 2", "Item 3"});
	combo.setEditable(true);
	centerPane.add(combo, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 0, 0, 0), 0, 0));
	frame.getContentPane().add(centerPane);
	frame.setSize(300, 200);
	frame.setVisible(true);
}
@DevCharly
Copy link
Collaborator

Thanks. I agree with you. That do not feel right.

Is also the case for JSpinner.
Will rework it...

DevCharly added a commit that referenced this issue Jul 5, 2021
DevCharly added a commit that referenced this issue Jul 5, 2021
…d to the component border so that it behaves like plain text field (issue #330)
@DevCharly
Copy link
Collaborator

@Chrriis have reworked internals of combo box and spinner UI delegates.
The internal text field now occupies the whole area within the border.
For not editable combo box, the renderer uses the whole area within the border.

Before:
image image

After:
image image

This affects editors with custom borders (#102) and custom renderers.

Before:
image

After:
image

@DevCharly DevCharly added this to the 1.4 milestone Jul 5, 2021
@Chrriis
Copy link
Contributor Author

Chrriis commented Jul 13, 2021

I gave it a try, and everything seems to work as expected, even in some awful compositing cases! Thanks! 👍

DevCharly added a commit that referenced this issue Sep 22, 2021
…f round edges are enabled (similar to issue #382; regression since fixing #330 in FlatLaf 1.4)
DevCharly added a commit that referenced this issue Nov 11, 2021
…f round edges are enabled (similar to issue #382; regression since fixing #330 in FlatLaf 1.4)

(cherry picked from commit 02f3239)
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