From 0dba9265be9d874368f991420a32430fbbccd379 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Wed, 6 Apr 2022 18:53:45 +0200 Subject: [PATCH] ToolBar: fixed endless loop in focus navigation that may occur under special circumstances (issue #505) --- CHANGELOG.md | 2 ++ .../src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b229d2f..7946f7de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ FlatLaf Change Log - Native window decorations (Windows 10/11 only): Fixed wrong window title character encoding used in Windows taskbar. (issue #502) +- ToolBar: Fixed endless loop in focus navigation that may occur under special + circumstances. (issue #505) ## 2.1 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java index 57f30740..fa241700 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolBarUI.java @@ -256,11 +256,15 @@ public class FlatToolBarUI default: return; } - for( int i = focusedCompIndex + add; i != focusedCompIndex; i += add ) { + int i = focusedCompIndex; + for(;;) { + i += add; if( i < 0 ) i = count - 1; else if( i >= count ) i = 0; + if( i == focusedCompIndex ) + break; Component c = toolBar.getComponentAtIndex( i ); if( canBeFocusOwner( c ) ) {