From 6a19f8353953701f7245650fd8833d2a6cdbc50c Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 11 Sep 2016 11:10:51 +0800 Subject: [PATCH] Avoid `bad position` issues --- source/net/filebot/ui/rename/FormatDialog.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/net/filebot/ui/rename/FormatDialog.java b/source/net/filebot/ui/rename/FormatDialog.java index cebf632b..de6e6150 100644 --- a/source/net/filebot/ui/rename/FormatDialog.java +++ b/source/net/filebot/ui/rename/FormatDialog.java @@ -305,10 +305,17 @@ public class FormatDialog extends JDialog { } public void setFormatCode(String text) { + // update format code editor.setText(text); - editor.scrollRectToVisible(new Rectangle(0, 0)); // reset scroll - editor.setCaretPosition(text.length()); // scroll to end of format - editor.requestFocusInWindow(); + + // scroll to last character and focus + try { + editor.scrollRectToVisible(new Rectangle(0, 0)); // reset scroll + editor.setCaretPosition(text.length()); // scroll to end of format + editor.requestFocusInWindow(); + } catch (Exception e) { + log.warning(e::getMessage); + } } private RSyntaxTextArea createEditor() {