Skip to content

Commit 1d21378

Browse files
matthijskooijmanfacchinm
authored andcommitted
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 f57b90c commit 1d21378

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
@@ -1608,7 +1608,7 @@ public void selectTab(final int index) {
16081608
SwingUtilities.invokeLater(() -> {
16091609
codePanel.removeAll();
16101610
codePanel.add(tabs.get(index), BorderLayout.CENTER);
1611-
tabs.get(index).requestFocus(); // get the caret blinking
1611+
tabs.get(index).requestFocusInWindow(); // get the caret blinking
16121612
// For some reason, these are needed. Revalidate says it should be
16131613
// automatically called when components are added or removed, but without
16141614
// 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
@@ -147,7 +147,7 @@ public void edit(String message, String dflt) {
147147
editField.setVisible(true);
148148
editField.setText(dflt);
149149
editField.selectAll();
150-
editField.requestFocus();
150+
editField.requestFocusInWindow();
151151

152152
repaint();
153153
}

app/src/processing/app/EditorTab.java

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

602602
@Override
603-
public void requestFocus() {
603+
public boolean requestFocusInWindow() {
604604
/** If focus is requested, focus the textarea instead. */
605-
textarea.requestFocus();
605+
return textarea.requestFocusInWindow();
606606
}
607607

608608
}

0 commit comments

Comments
 (0)