Label Text TextField PasswordField
Label
Label label = new Label ( ) ;
label. setText ( "Label" ) ;
label. setFont ( Font. font ( 30 ) ) ;
label. setTextFill ( Paint. valueOf ( "#088" ) ) ;
Text
Font. getFamilies ( ) ;
Text text = new Text ( ) ;
text. setFill ( Paint. valueOf ( "#ccc" ) ) ;
text. setStroke ( Paint. valueOf ( "#0ac" ) ) ;
text. setStrokeWidth ( 2 ) ;
text. setStrokeType ( StrokeType. OUTSIDE) ;
text. setUnderline ( true ) ;
text. setStrikethrough ( true ) ;
text. setSmooth ( true ) ;
text. setFontSmoothingType ( FontSmoothingType. LCD) ;
TextField
TextField textField = new TextField ( ) ;
textField. setText ( "TextField" ) ;
textField. setFont ( Font. font ( 30 ) ) ;
Tooltip tooltip = new Tooltip ( "请输入XXX" ) ;
textField. setTooltip ( tooltip) ;
textField. setPromptText ( "请输入XXX" ) ;
监听输入
textField. textProperty ( ) . addListener ( new ChangeListener < String> ( ) {
@Override
public void changed ( ObservableValue< ? extends String > observable, String oldValue, String newValue) {
if ( newValue. length ( ) > 8 ) {
textField. setText ( oldValue) ;
}
}
} ) ;
监听选择
textField. 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) ;
}
} ) ;
PasswordField
PasswordField passwordField = new PasswordField ( ) ;