-
-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add focus to first field in macro popup
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
ugs-core/src/com/willwinder/universalgcodesender/RequestFocusListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.willwinder.universalgcodesender; | ||
|
||
import java.awt.Component; | ||
import java.awt.Window; | ||
import java.awt.event.HierarchyEvent; | ||
import java.awt.event.HierarchyListener; | ||
import java.awt.event.WindowAdapter; | ||
import java.awt.event.WindowEvent; | ||
import javax.swing.SwingUtilities; | ||
|
||
public class RequestFocusListener implements HierarchyListener { | ||
|
||
@Override | ||
public void hierarchyChanged(HierarchyEvent e) { | ||
final Component c = e.getComponent(); | ||
if (c.isShowing() && (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) { | ||
Window toplevel = SwingUtilities.getWindowAncestor(c); | ||
toplevel.addWindowFocusListener(new WindowAdapter() { | ||
|
||
@Override | ||
public void windowGainedFocus(WindowEvent e) { | ||
c.requestFocus(); | ||
} | ||
}); | ||
} | ||
} | ||
} |