Created
June 22, 2017 12:13
-
-
Save TheItachiUchiha/20e1299a9dd95a0ee7d180343530a67c to your computer and use it in GitHub Desktop.
Bind Button Disable Property to ListView Selection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.ListView; | |
import javafx.scene.layout.BorderPane; | |
import javafx.scene.layout.HBox; | |
import javafx.stage.Stage; | |
public class ShowCaseBooleanProperty extends Application { | |
public void start(Stage primaryStage) { | |
primaryStage.setTitle("Hello World!"); | |
ListView<String> lv = new ListView<>(); | |
lv.getItems().addAll("Example"); | |
Button clearSelection = new Button("Clear Selection"); | |
clearSelection.setOnAction(e -> lv.getSelectionModel().select(null)); | |
Button btnBindButtonToProp = new Button("Button -> Prop"); | |
BorderPane bp = new BorderPane(); | |
bp.setCenter(lv); | |
HBox hb = new HBox(); | |
hb.getChildren().addAll(btnBindButtonToProp, clearSelection); | |
bp.setBottom(hb); | |
btnBindButtonToProp.disableProperty().bind(lv.getSelectionModel().selectedItemProperty().isNotNull()); | |
primaryStage.setScene(new Scene(bp, 400, 200)); | |
primaryStage.show(); | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot, line 27 really helped me in a uni project! 👍