Created
November 14, 2025 21:21
-
-
Save sedj601/abefc00be5f8beda29b7a5dceb4343ab to your computer and use it in GitHub Desktop.
Feed back to StackOverflow Question. https://stackoverflow.com/q/79819532/2423906
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
| package sed.home.javafxfxmltestingground; | |
| import javafx.application.Application; | |
| import javafx.fxml.FXMLLoader; | |
| import javafx.scene.Parent; | |
| import javafx.scene.Scene; | |
| import javafx.stage.Stage; | |
| import java.io.IOException; | |
| /** | |
| * JavaFX App | |
| */ | |
| public class App extends Application { | |
| private static Scene scene; | |
| @Override | |
| public void start(Stage stage) throws IOException { | |
| scene = new Scene(loadFXML("primary"), 640, 480); | |
| stage.setScene(scene); | |
| stage.show(); | |
| } | |
| static void setRoot(String fxml) throws IOException { | |
| scene.setRoot(loadFXML(fxml)); | |
| } | |
| private static Parent loadFXML(String fxml) throws IOException { | |
| FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml")); | |
| return fxmlLoader.load(); | |
| } | |
| public static void main(String[] args) { | |
| launch(); | |
| } | |
| } |
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
| <?xml version="1.0" encoding="UTF-8"?> | |
| <?import javafx.scene.layout.VBox?> | |
| <?import javafx.scene.control.Label?> | |
| <?import javafx.scene.control.Button?> | |
| <?import javafx.scene.control.ComboBox?> | |
| <?import javafx.geometry.Insets?> | |
| <VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sed.home.javafxfxmltestingground.PrimaryController"> | |
| <padding> | |
| <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" /> | |
| </padding> | |
| <children> | |
| <ComboBox fx:id="cb1" onAction="#OnCB1Selected" /> | |
| <ComboBox fx:id="cb2" onAction="#OnCB2Selected" /> | |
| <ComboBox fx:id="cb3" onAction="#OnCB3Selected" /> | |
| </children> | |
| </VBox> |
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
| package sed.home.javafxfxmltestingground; | |
| import java.util.ArrayList; | |
| import javafx.collections.FXCollections; | |
| import javafx.event.ActionEvent; | |
| import javafx.fxml.FXML; | |
| import javafx.scene.control.ComboBox; | |
| public class PrimaryController { | |
| @FXML | |
| private ComboBox<String> cb1; | |
| @FXML | |
| private ComboBox<String> cb2; | |
| @FXML | |
| private ComboBox<String> cb3; | |
| private final ArrayList<ComboBox<String>> comboBoxes = new ArrayList(); | |
| private ComboBox<String> currentComboBox; | |
| public void initialize() { | |
| ArrayList<String> strsList = new ArrayList(); | |
| strsList.add("A"); | |
| strsList.add("B"); | |
| strsList.add("C"); | |
| strsList.add("D"); | |
| strsList.add("E"); | |
| strsList.add("F"); | |
| strsList.add("G"); | |
| strsList.add("H"); | |
| cb1.setItems(FXCollections.observableArrayList(new ArrayList(strsList))); | |
| cb2.setItems(FXCollections.observableArrayList(new ArrayList(strsList))); | |
| cb3.setItems(FXCollections.observableArrayList(new ArrayList(strsList))); | |
| comboBoxes.add(cb1); | |
| comboBoxes.add(cb2); | |
| comboBoxes.add(cb3); | |
| } | |
| @FXML | |
| private void OnCB1Selected(ActionEvent actionEvent) { | |
| currentComboBox = (ComboBox)actionEvent.getSource(); | |
| removeItemFromComboBoxes(); | |
| } | |
| @FXML | |
| private void OnCB2Selected(ActionEvent actionEvent) { | |
| currentComboBox = (ComboBox)actionEvent.getSource(); | |
| removeItemFromComboBoxes(); | |
| } | |
| @FXML | |
| private void OnCB3Selected(ActionEvent actionEvent) { | |
| currentComboBox = (ComboBox)actionEvent.getSource(); | |
| removeItemFromComboBoxes(); | |
| } | |
| private void removeItemFromComboBoxes() | |
| { | |
| if(currentComboBox.getValue() != null) | |
| { | |
| comboBoxes.forEach(node -> { | |
| if(node != currentComboBox) | |
| { | |
| node.getItems().remove(currentComboBox.getValue()); | |
| } | |
| else | |
| { | |
| //Use if needed! | |
| } | |
| }); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment