Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望根据状态设置 JavaFX ToggleButton 的标题:
命令式 Java 代码:
tgBtn.setText( tgBtn.isSelected() ? "Stop" : "Start" );
我希望使用 JavaFX 绑定,但我错过了“三元”运算符:
tgBtn.textProperty().bind( tgBtn.selectedProperty().asString());
使用此绑定,按钮的文本变为:
你能建议一个显示“开始”/“停止”的绑定吗?
tgBtn.textProperty().bind( Bindings.when(tgBtn.selectedProperty()) .then("Stop") .otherwise("Start") );