-
-
Notifications
You must be signed in to change notification settings - Fork 265
-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
focus handling using JToolBar is not correct #346
Comments
Toolbar buttons in FlatLaf are not focusable: FlatLaf/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java Lines 57 to 63 in c708205
The reason for this is that in modern applications, the toolbar is not focusable these days. One exception is Firefox where you use Currently there is no way to change this in FlatLaf, but I'll make this configurable. A workaround is to invoke JButton button = new JButton( "save" );
toolbar.add( button );
button.setFocusable( true ); But currently no focus indicator is painted for FlatLaf toolbar buttons. I'll add this for 1.4. Anyway, IMHO you should not depend on focus events in your save method. Better explicitly commit. E.g. when getting value from table. |
You are right about the focus behavior, and this is actually a bigger problem; if the user is editing some field and then triggers a save action -being it via the toolbar, menu, or keyboard shortcut- he expects the edit to be committed prior to the save action being executed. Which I feel is a perfectly sensible expectation, at least I expect this. Consider Excel where the edit in a cell is not committed when pressing ctrl+s. I figure one could scan the whole component tree for components still in edit mode... Hm. The focus lost specifically for tables is widely recognized. It is something that is haunting the table in JavaFX, and in Swing has is a special property that can be set on JTable to make sure commit-on-focus-lost is done (table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE)). Thank you for making it configurable. However, IMHO, the default behavior of FlatLaF toolbar is a breaking change to the expected behavior, every other LaF moves the focus upon button click. So I would suggest making the default to move the focus :-). |
fixed focusable state when switching to/from other Laf
FlatLaf 1.4 is now out and you can reenable focusable toolbar buttons with: UIManager.put( "ToolBar.focusableButtons", true ); The default value is still Have also implemented a focus traversal policy for the toolbar,
This makes the "tab" navigation easier because it is no longer press |
Great! I'll give this a try soon! |
…ing arrow keys to navigate in focusable buttons (related to issue #346)
…of toolbar: - arrow keys move focus within toolbar (provided by `BasicToolBarUI`) - tab-key moves focus out of toolbar - if moving focus into the toolbar, focus recently focused toolbar button (issue #346)
FlatLaf 2.0-rc1 contains some toolbar improvements. Arrow-keys-only navigationIf UI property
This is the same navigation as used in Firefox. FloatableToolbars are no longer floatable by default (dots on left side of toolbar that allows dragging toolbar). DocsThe UI properties are documented here: |
If you have a button in a JToolBar then normally when you click that button the focus should be pulled away from any editing component. This does not happen. This results in situations where a user clicks on "save" and the edit is not committed prior to the save action.
Java 15, FlatLAF 1.3.
Below a small application demonstrating this. Just click on the toolbar button and see if the editing textfield or table is committed. Behavior is different from when the button at the bottom is clicked.
The text was updated successfully, but these errors were encountered: