Users on Windows were reporting issues with dialog boxes and windows not getting proper focus when they open. This was causing problems such as:
- Dialog boxes appearing but not being active/focused
- Typing not working in dialog text fields immediately
- Keyboard navigation not working properly
- Inconsistent focus behavior across different dialogs
- Some dialogs used
windowOpenedevents for focus management - Others used
windowActivatedevents - Mixed approaches created unpredictable behavior, especially on Windows
- Most dialogs used
requestFocus()instead ofrequestFocusInWindow() requestFocus()can fail on Windows due to focus stealing prevention policiesrequestFocusInWindow()is more reliable across platforms
- Dialog positioning (
setLocationRelativeTo()) and focus requests happened simultaneously - Windows requires proper sequencing of these operations
- Dialogs weren't explicitly brought to front on Windows
- Internal frames had similar issues
File: DialogUtils.java
-
Improved
closeOnEscapeKey()method:- Added
toFront()call for better Windows compatibility - Changed from
requestFocus()torequestFocusInWindow() - Added
SwingUtilities.invokeLater()for proper sequencing
- Added
-
New
closeOnEscapeKeyWithFocus()method:- Allows specifying a component to receive focus
- Handles focus management centrally
- Uses Windows-compatible focus techniques
Files: NameDialog.java, SaveProjectAsDialog.java, NewAgentDialog.java, FindDialog.java, ReplaceInProjectDialog.java
-
Removed inconsistent focus listeners:
- Eliminated custom
windowActivatedandwindowOpenedhandlers - Centralized focus management through
DialogUtils
- Eliminated custom
-
Simplified focus handling:
- Use
DialogUtils.closeOnEscapeKeyWithFocus()consistently - Pass the specific component that should receive focus
- Use
Files: NamePanel.java, AgentNamePanel.java, RangePanel.java, EnumPanel.java, FindPanel.java
- Changed focus methods:
- Replaced
requestFocus()withrequestFocusInWindow() - More reliable on Windows platforms
- Replaced
File: MainFrame.java
-
Updated
WindowMenuListener.actionPerformed():- Added
SwingUtilities.invokeLater()for proper sequencing - Added
requestFocusInWindow()call for internal frames
- Added
-
Enhanced
selectNewInternalFrame()method:- Added
SwingUtilities.invokeLater()wrapper - Improved focus handling for internal frames
- Added
- Unified focus management approach across all dialogs
- Windows-specific focus handling patterns implemented
- Proper event sequencing for cross-platform compatibility
- Dialogs now properly receive focus when opened
- Text fields are immediately ready for typing
- Keyboard navigation works consistently
- ESC key handling is more reliable
- Centralized focus management in
DialogUtils - Consistent patterns across all dialog classes
- Easier maintenance and debugging
- Use of
requestFocusInWindow()instead ofrequestFocus() - Proper use of
SwingUtilities.invokeLater()for event sequencing - Added
toFront()calls where needed
-
Focus Stealing Prevention:
- Windows has aggressive focus stealing prevention
requestFocusInWindow()respects these policies better thanrequestFocus()
-
Event Timing:
- Windows requires proper sequencing of positioning and focus operations
SwingUtilities.invokeLater()ensures operations happen in correct order
-
Z-Order Management:
- Explicit
toFront()calls ensure dialogs appear above other windows - Important for proper focus behavior on Windows
- Explicit
-
Dialog Focus:
- Open various dialogs (New Agent, Save As, Find, etc.)
- Verify text fields are immediately ready for typing
- Test that cursor appears in the correct field
-
Keyboard Navigation:
- Test ESC key to close dialogs
- Test Tab navigation between fields
- Test Enter key for default actions
-
Window Management:
- Test with multiple internal frames open
- Verify proper focus when switching between frames
- Test minimizing/restoring windows
- Test specifically on Windows 10/11
- Test with different window managers
- Test with multiple monitors
- Test with accessibility software
-
Additional Improvements:
- Consider implementing platform-specific focus delays if needed
- Monitor for any remaining focus issues in complex dialogs
- Consider adding focus indicators for better accessibility
-
Monitoring:
- Watch for user feedback on focus behavior
- Consider adding telemetry for focus-related issues
- Monitor performance impact of changes
DialogUtils.java- Enhanced focus management utilitiesNameDialog.java- Updated focus handlingSaveProjectAsDialog.java- Updated focus handlingNewAgentDialog.java- Updated focus handlingFindDialog.java- Updated focus handlingReplaceInProjectDialog.java- Updated focus handlingNamePanel.java- Updated focus methodAgentNamePanel.java- Updated focus methodRangePanel.java- Updated focus methodEnumPanel.java- Updated focus methodFindPanel.java- Updated focus methodMainFrame.java- Enhanced internal frame focus handling
These changes should significantly improve the focus behavior for Windows users while maintaining compatibility with other platforms.