Skip to content

Commit 633ec5f

Browse files
Replace requestFocus() by requestFocusInWindow() where applicable
The former gives focus to the window in which a component is present, while the latter only changes the focus within the current window (not focusing the window itself if it is not focused yet). Java documentation recommends changing `requestFocusInWindow()` where possible, due to some platform-dependent behaviour in `requestFocus()`. When focusing the serial monitor and plotter, `requestFocus()` is still used, since then the focused window *should* change.
1 parent 3e2797c commit 633ec5f

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

app/src/processing/app/Editor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ public void selectTab(final int index) {
16171617
SwingUtilities.invokeLater(() -> {
16181618
codePanel.removeAll();
16191619
codePanel.add(tabs.get(index), BorderLayout.CENTER);
1620-
tabs.get(index).requestFocus(); // get the caret blinking
1620+
tabs.get(index).requestFocusInWindow(); // get the caret blinking
16211621
// For some reason, these are needed. Revalidate says it should be
16221622
// automatically called when components are added or removed, but without
16231623
// it, the component switched to is not displayed. repaint() is needed to

app/src/processing/app/EditorStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void edit(String message, String dflt) {
143143
editField.setVisible(true);
144144
editField.setText(dflt);
145145
editField.selectAll();
146-
editField.requestFocus();
146+
editField.requestFocusInWindow();
147147

148148
repaint();
149149
}

app/src/processing/app/EditorTab.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,9 @@ public String getCurrentKeyword() {
575575
}
576576

577577
@Override
578-
public void requestFocus() {
578+
public boolean requestFocusInWindow() {
579579
/** If focus is requested, focus the textarea instead. */
580-
textarea.requestFocus();
580+
return textarea.requestFocusInWindow();
581581
}
582582

583583
}

0 commit comments

Comments
 (0)