Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

update textarea and scroll

 
Max Pic
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.
in my initialize method, i've:

of TextArea object, and:


logString is SimpleStringProperty, that I change:


well...
when variable logString change the content of textarea change with the value of logString, i see "i'm here two" in the console but not "i'm here" in the textarea and it isn't scroll at the bottom... WHY ???


 
John Damien Smith
Ranch Hand
Posts: 299
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. You can't modify a unidirectionally bound property (only the thing the property is bound to can change it).

To see an example, run the following program:

Output will be:
java.lang.RuntimeException: A bound value cannot be set.


So your program throws an exception and you never catch it, so you never know.

Note, you can modify a bidirectionally bound property, in which case both properties will change their values.

2. Even if modifying the property did work, your program would go into an infinite loop.

You listen for changes on the property, then always change the property when the property changes, so it will be forever changing.
 
Max Pic
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok. thanks.
i've modified my code in initalize method:



it now works. but i ask: is it the best way to update (and scroll) javafx textarea?


2nd question:
when i update logString variable, I must to use "Platform.runLater" or not?

 
John Damien Smith
Ranch Hand
Posts: 299
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> is it the best way to update (and scroll) javafx textarea?

I wouldn't use a textarea for to implement a logging component in JavaFX, I would use a listview, add each log entry as an item to the collection backing the listview and scroll the listview to the item.

> update logString variable, I must to use "Platform.runLater" or not?

If logstring is being updated on the JavaFX application thread, then runLater is not required, otherwise you need to wrap updates to it in platform.runlater so that it is updated on the JavaFX application thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic