26521

JavaFX TextArea with listener gives: “java.lang.IllegalArgumentException: The start must be

Question:

I am getting the exception when trying to change text in the text property listener. The exception is exactly the same is <a href="https://stackoverflow.com/questions/30465313/javafx-textfield-with-listener-gives-java-lang-illegalargumentexception-the-s" rel="nofollow">this question</a>. I used TextArea instead of TextField, but I think the source of the bug is the same. It's in the "TextInputControl.java". It seems to be Java 8's bug.

@FXML private TextArea ta; ta.setText("12-"); // pre-set text ta.textProperty().addListener((observable, oldValue, newValue) -> { ta.setText("1"); // changed text });

This causes the exception on my machine. I have JDK 1.8.0_51 on Win 7 64-bit. However, this dosen't cause the exception if I switch back to JDK 1.8.0_25.

I tired a range of "pre-set text" and "changed text" combinations and I found that, generally, if it's more like to cause the exception when the length of "changed text" is short then the "pre-set text".

Is there an workaround for this issue? Or did I make mistakes somewhere?

Thanks for the help.

<strong>Edit</strong>: The following code will reproduce the issue. I tested with jre 8u60, and the issue still exists.

public class Main extends Application { @Override public void start(Stage primaryStage) { try { TextArea ta = new TextArea(); ta.setText("12-"); // pre-set text ta.textProperty().addListener((observable, oldValue, newValue) -> { ta.setText("1"); // changed text }); AnchorPane root = new AnchorPane(); root.getChildren().addAll(ta); Scene scene = new Scene(root,400,400); primaryStage.setScene(scene); primaryStage.show(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { launch(args); } }

After creating the window, the TextArea will show "12-". By trying to insert a character anywhere, the TextArea will change to "1" but with the following exception produced:

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: The start must be <= the end at javafx.scene.control.TextInputControl.getText(TextInputControl.java:446) at javafx.scene.control.TextInputControl.updateContent(TextInputControl.java:564) at javafx.scene.control.TextInputControl.replaceText(TextInputControl.java:548) at com.sun.javafx.scene.control.behavior.TextAreaBehavior.replaceText(TextAreaBehavior.java:305) at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.defaultKeyTyped(TextInputControlBehavior.java:238) at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callAction(TextInputControlBehavior.java:139) at com.sun.javafx.scene.control.behavior.TextAreaBehavior.callAction(TextAreaBehavior.java:259) at com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:218) at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callActionForEvent(TextInputControlBehavior.java:127) at com.sun.javafx.scene.control.behavior.BehaviorBase.lambda$new$74(BehaviorBase.java:135) at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Scene$KeyHandler.process(Scene.java:3964) at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3910) at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2040) at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2501) at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:197) at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:147) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$354(GlassViewEventHandler.java:228) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:227) at com.sun.glass.ui.View.handleKeyEvent(View.java:546) at com.sun.glass.ui.View.notifyKey(View.java:966) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191) at java.lang.Thread.run(Thread.java:745)

Clearing before changing text doesn't help either because even just clearing the text, ie. ta.clear();, would cause the same exception. Any ideas? Is there a JIRA ticket about this already?

Answer1:

To me it seems like a bug. Wouldnt be the first time something like this happens from one version to the other. Most of the time I have a look at the <a href="https://javafx-jira.kenai.com" rel="nofollow">JavaFX Jira</a> and see if there are any open issues. I didnt find it at this point. As a workaround I would suggest to use another component, probably the Label instead of the TextArea if you only want to display text.

Edit:

Have a look at:

<a href="https://bugs.openjdk.java.net/browse/JDK-8081700" rel="nofollow">https://bugs.openjdk.java.net/browse/JDK-8081700</a>

Recommend

  • ImageView won't display the Image when it comes from project space
  • JavaFx 2.x TableView binding columns
  • JavaFX - How to get FXML Controller? [duplicate]
  • Making games with JNativeHook
  • Adding Event listener to mainScene in Javafx using fxml
  • Using initialize method in a controller in FXML?
  • How to get mouse position in chart-space
  • ScrollPane jumps to top when deleting nodes
  • How to reduce the time delay to reach run method of Runnable class using ExecutorService Java
  • IBM DevOps Pipeline: How to Access Artifacts from Previous Job?
  • Parenthesis() and SQL Query Performance
  • How to display a tooltip according to mouse position? - JavaFX
  • How to disable all widgets inside Panel or inside Composite?
  • JBoss External Properties Files in Classpath
  • how to avoid repetitive constructor in children
  • htaccess add www if not subdomain, if subdomain remove www
  • Highlight and Bold text in JTextPane
  • Debugging ASP.NET on a built-in web server suddenly stops
  • how to do an event when i swipe from fragment to the other
  • Why value captured by reference in lambda is broken? [duplicate]
  • Update CALayer sublayers immediately
  • Jenkins: How To Build multiple projects from a TFS repository?
  • JFileChooser in front of fullscreen Swing application
  • C# - Serializing and deserializing static member
  • Possible to stop flickering java tooltip in heavyweight mode?
  • output of program is not same as passed argument
  • Sending data from AppleScript to FileMaker records
  • Akka Routing: Reply's send to router ends up as dead letters
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • How to include full .NET prerequisite for Wix Burn installer
  • python regex in pyparsing
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • Android Google Maps API OnLocationChanged only called once
  • Is it possible to post an object from jquery to bottle.py?
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • How can i traverse a binary tree from right to left in java?
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?