From 439f80d23ec979354212a668a7d4a9312ba2ad49 Mon Sep 17 00:00:00 2001 From: ray Date: Tue, 1 Mar 2005 03:25:22 +0000 Subject: [PATCH] Fixed nonserious exception that got thrown when more than one digit was selected and a replacement was entered. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1601 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../src/java/com/samskivert/swing/IntField.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/swing/IntField.java b/projects/samskivert/src/java/com/samskivert/swing/IntField.java index d8f3839a..152b484f 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/IntField.java +++ b/projects/samskivert/src/java/com/samskivert/swing/IntField.java @@ -143,12 +143,16 @@ public class IntField extends JTextField { boolean wouldaBeenEqual = current.equals(potential); potential = transform(potential); + boolean selection = (getSelectionEnd() != getSelectionStart()); // we only change it if it needs changing if (!current.equals(potential) || // or if it would have been the same pre-transforming // and there is a selection (IE undo the selection) - (wouldaBeenEqual && - (getSelectionEnd() != getSelectionStart()))) { + (wouldaBeenEqual && selection)) { + if (selection) { + // undo the selection to not cause an exception + setCaretPosition(0); + } fb.replace(0, doc.getLength(), potential, null); } }