From 1d21378a5fcaa53de7ff9468662dc38aabc8ee71 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 11 Dec 2015 17:14:45 +0100 Subject: [PATCH] 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. --- app/src/processing/app/Editor.java | 2 +- app/src/processing/app/EditorStatus.java | 2 +- app/src/processing/app/EditorTab.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 87559f10e..dfe789ad5 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1608,7 +1608,7 @@ public class Editor extends JFrame implements RunnerListener { SwingUtilities.invokeLater(() -> { codePanel.removeAll(); codePanel.add(tabs.get(index), BorderLayout.CENTER); - tabs.get(index).requestFocus(); // get the caret blinking + tabs.get(index).requestFocusInWindow(); // get the caret blinking // For some reason, these are needed. Revalidate says it should be // automatically called when components are added or removed, but without // it, the component switched to is not displayed. repaint() is needed to diff --git a/app/src/processing/app/EditorStatus.java b/app/src/processing/app/EditorStatus.java index 4d5ebbad2..2271c436d 100644 --- a/app/src/processing/app/EditorStatus.java +++ b/app/src/processing/app/EditorStatus.java @@ -147,7 +147,7 @@ public class EditorStatus extends JPanel { editField.setVisible(true); editField.setText(dflt); editField.selectAll(); - editField.requestFocus(); + editField.requestFocusInWindow(); repaint(); } diff --git a/app/src/processing/app/EditorTab.java b/app/src/processing/app/EditorTab.java index 6d2ce629d..59f0a9e7c 100644 --- a/app/src/processing/app/EditorTab.java +++ b/app/src/processing/app/EditorTab.java @@ -600,9 +600,9 @@ public class EditorTab extends JPanel implements SketchCode.TextStorage { } @Override - public void requestFocus() { + public boolean requestFocusInWindow() { /** If focus is requested, focus the textarea instead. */ - textarea.requestFocus(); + return textarea.requestFocusInWindow(); } } \ No newline at end of file