TextArea
TextArea textArea = new TextArea ( ) ;
textArea. setPrefColumnCount ( 20 ) ;
textArea. setPrefRowCount ( 30 ) ;
textArea. setPromptText ( "PromptText" ) ;
textArea. setWrapText ( true ) ;
textArea. setText ( "setText" ) ;
textArea. appendText ( "appendText" ) ;
textArea. insertText ( 7 , "|" ) ;
textArea. deleteText ( 3 , 7 ) ;
textArea. replaceText ( 0 , 3 , "SET" ) ;
textArea. positionCaret ( 3 ) ;
textArea. selectAll ( ) ;
textArea. textProperty ( ) . addListener ( new ChangeListener < String> ( ) {
@Override
public void changed ( ObservableValue< ? extends String > observable, String oldValue, String newValue) {
System. out. println ( "observable = " + observable + ", oldValue = " + oldValue + ", newValue = " + newValue) ;
}
} ) ;
textArea. selectedTextProperty ( ) . addListener ( new ChangeListener < String> ( ) {
@Override
public void changed ( ObservableValue< ? extends String > observable, String oldValue, String newValue) {
System. out. println ( "observable = " + observable + ", oldValue = " + oldValue + ", newValue = " + newValue) ;
}
} ) ;
textArea. scrollTopProperty ( ) . addListener ( new ChangeListener < Number> ( ) {
@Override
public void changed ( ObservableValue< ? extends Number > observable, Number oldValue, Number newValue) {
System. out. println ( "observable = " + observable + ", oldValue = " + oldValue + ", newValue = " + newValue) ;
}
} ) ;
TextFormatter
TextField textField = new TextField ( ) ;
textField. setTextFormatter ( new TextFormatter < String> ( new UnaryOperator < Change> ( ) {
@Override
public Change apply ( Change change) {
if ( change. getText ( ) . matches ( "[0-9a-zA-Z]" ) ) {
return change;
}
return null;
}
} ) ) ;