How disable JavaFX Text -


how disable javafx text

text t = new text();  t.settext("this text sample");  t.setdisable(true); //it not work 

solution

you can style text visually, looks disabled, if wish. solution below binds opacity setting disabled setting of text.

disabled

import javafx.application.application; import javafx.beans.binding.bindings; import javafx.geometry.insets; import javafx.scene.scene; import javafx.scene.layout.vbox; import javafx.scene.text.text; import javafx.stage.stage;  public class disabledtext extends application {     public static void main(string[] args) {         launch(args);     }      @override     public void start(stage stage) {         text enabledtext = new text("enabled");          text disabledtext = new text("disabled");         disabledtext.opacityproperty().bind(                 bindings.when(                         disabledtext.disabledproperty())                         .then(0.4)                         .otherwise(1)         );         disabledtext.setdisable(true);          vbox layout = new vbox(10, enabledtext, disabledtext);         layout.setpadding(new insets(10));         stage.setscene(new scene(layout));         stage.show();     } } 

notes

you might able accomplish through css rather binding, didn't try option.

in general, many times better off using label text lot of things includes more flexibility , functionality.

background

even though user can't interact directly text, disabling text has no effect, guess looking text other things when disabled.

normally happens when control such menu item or button disabled, css pseudo-class :disabled set on control. when occurs, default modena.css stylesheet javafx 8 modify opacity control -fx-opacity: 0.4;. changes visual control appears though grayed out, low opacity makes control looks faded.

text built base drawing shape. base drawing shapes in java deliberately don't rely on css (though css can used them if needed - see css reference guide info on default css rules apply shapes). if scene doesn't use layout panes or controls, standard modena.css stylesheet not loaded , css processing not applied scene (for efficiency reasons that, instance, write high performance game did not use css processing). css processing text not required and, if used, limited in scope.


Comments