List of usage examples for javafx.scene.control ComboBox getItems
public final ObservableList<T> getItems()
From source file:Main.java
@Override public void start(Stage stage) { stage.setTitle("ComboBoxSample"); Scene scene = new Scene(new Group(), 450, 250); ComboBox emailComboBox = new ComboBox(); emailComboBox.getItems().addAll("A", "B", "C", "D", "E"); emailComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() { @Override//from ww w.j av a 2 s . co m public ListCell<String> call(ListView<String> param) { final ListCell<String> cell = new ListCell<String>() { { super.setPrefWidth(100); } @Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (item != null) { setText(item); if (item.contains("A")) { setTextFill(Color.RED); } else if (item.contains("B")) { setTextFill(Color.GREEN); } else { setTextFill(Color.BLACK); } } else { setText(null); } } }; return cell; } }); GridPane grid = new GridPane(); grid.setVgap(4); grid.setHgap(10); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(new Label("To: "), 0, 0); grid.add(emailComboBox, 1, 0); Group root = (Group) scene.getRoot(); root.getChildren().add(grid); stage.setScene(scene); stage.show(); }
From source file:com.bdb.weather.display.preferences.ColorPreferencePanel.java
public ColorPreferencePanel() { VBox vbox = new VBox(); GridPane colorPanel = new GridPane(); for (ColorPreferenceEntry entry : entries2) { ColorPicker colorPicker = new ColorPicker(preferences.getColorPref(entry.preferenceName)); entry.button = colorPicker;// w ww . ja v a 2s . c o m colorPanel.add(new Label(entry.preferenceName), 0, entry.row); colorPanel.add(colorPicker, 1, entry.row); } GridPane plotColorPanel = new GridPane(); int gridx = 0; int gridy = 0; // // Layout the column headers // for (int i = 0; i < COLOR_COL_HEADERS.length; i++) { gridx = i; plotColorPanel.add(new Label(COLOR_COL_HEADERS[i]), gridx, gridy); } // // Layout the row leaders // //c.anchor = GridBagConstraints.EAST; for (String header : COLOR_ROW_HEADERS) { gridx = 0; gridy++; plotColorPanel.add(new Label(header), gridx, gridy); gridx = 5; Set<String> names = ColorSchemeCollection.getColorSchemeNames(); ComboBox<String> scheme = new ComboBox<>(); scheme.getItems().addAll(names); scheme.setUserData(gridy); plotColorPanel.add(scheme, gridx, gridy); scheme.setOnAction((ActionEvent e) -> { ComboBox<String> cb = (ComboBox<String>) e.getSource(); applyColorScheme((Integer) cb.getUserData(), cb.getSelectionModel().getSelectedItem()); }); gridx = 6; CheckBox showSeries = new CheckBox(); showSeries.setUserData(gridy); plotColorPanel.add(showSeries, gridx, gridy); showSeries.setOnAction((ActionEvent e) -> { CheckBox cb = (CheckBox) e.getSource(); int row = (Integer) cb.getUserData(); for (ColorPreferenceEntry entry : entries) { if (entry.row == row) { addRemoveSeries(entry.preferenceName, cb.isSelected()); } } createSeriesData(); configureRenderer(); }); } //c.anchor = GridBagConstraints.CENTER; for (ColorPreferenceEntry entry : entries) { gridx = entry.column; gridy = entry.row; ColorPicker button = new ColorPicker(); button.setValue(preferences.getColorPref(entry.preferenceName)); //button.setPrefSize(10, 10); button.setUserData(entry); plotColorPanel.add(button, gridx, gridy); entry.button = button; } JFreeChart chart = ChartFactory.createXYLineChart("Example", "X Axis", "Y Axis", dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(renderer); ChartViewer graphExamplePanel = new ChartViewer(chart); vbox.getChildren().addAll(colorPanel, plotColorPanel); setTop(vbox); setCenter(graphExamplePanel); FlowPane buttonPanel = new FlowPane(); Button button = new Button("OK"); button.setOnAction((ActionEvent e) -> { saveData(); }); buttonPanel.getChildren().add(button); setBottom(buttonPanel); }
From source file:be.makercafe.apps.makerbench.editors.JFXMillEditor.java
/** * Creates the toolBar for the editor./*w w w . ja v a 2s . c o m*/ * * @return */ private ToolBar createToolBar() { ToolBar toolBar = new ToolBar(); toolBar.setOrientation(Orientation.HORIZONTAL); Button btnSave = GlyphsDude.createIconButton(MaterialDesignIcon.FLOPPY, "Save"); btnSave.setOnAction(this::handleSaveButton); Button btnExportSTL = GlyphsDude.createIconButton(MaterialDesignIcon.EXPORT, "Export GCODE"); btnExportSTL.setOnAction(this::handleExportAsGCodeFile); Button btnExportPNG = GlyphsDude.createIconButton(MaterialDesignIcon.CAMERA, "Export PNG"); btnExportPNG.setOnAction(this::handleExportAsPngFile); Button btnRun = GlyphsDude.createIconButton(MaterialDesignIcon.RUN, "Run"); btnRun.setOnAction(this::handleCompileAndRun); ToggleButton btnAutoCompile = GlyphsDude.createIconToggleButton(MaterialDesignIcon.AUTO_FIX, "Automatic run", null, ContentDisplay.LEFT); btnAutoCompile.setOnAction(this::handleAutoCompile); btnAutoCompile.setSelected(false); ToggleButton btn3DNav = GlyphsDude.createIconToggleButton(MaterialDesignIcon.ROTATE_3D, "3D Navigation ", null, ContentDisplay.LEFT); btn3DNav.setSelected(false); ComboBox cbxSourceExamples = new ComboBox(); cbxSourceExamples.getItems().addAll("TestCut"); this.cbxSourceExamples = cbxSourceExamples; // TODO: maybe cleaner way // to do this ? Button btnPasteSource = GlyphsDude.createIconButton(MaterialDesignIcon.CONTENT_PASTE, "Paste source"); btnPasteSource.setOnAction(this::handlePasteSource); toolBar.getItems().addAll(btnSave, btnExportSTL, btnExportPNG, new Separator(), btnRun, new Separator(), btnAutoCompile, new Separator(), cbxSourceExamples, btnPasteSource); return toolBar; }
From source file:mesclasses.view.RapportEleveController.java
private void drawGrid(File file) { Hyperlink link = new Hyperlink(file.getName()); link.setOnAction((event) -> openFile(file)); int rowIndex = fileGrid.addOnNewLineIfNecessary(link, 1, HPos.LEFT); ComboBox<String> typeBox = new ComboBox<>(); typeBox.getItems().addAll(Constants.FILE_TYPES); typeBox.getSelectionModel().select(selectedFileType.get()); typeBox.valueProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.equals(oldValue)) { try { EleveFileUtil.moveFileForEleve(eleve, file, newValue); selectFileType(newValue); refreshGrid();//from www.ja v a 2 s. com } catch (IOException e) { ModalUtil.alert("Impossible de dplacer le fichier", e.getMessage()); } } }); fileGrid.add(typeBox, 2, rowIndex, null); Button deleteBtn = Btns.deleteBtn(); deleteBtn.setOnAction(event -> { if (ModalUtil.confirm("Suppression du fichier", "Etes vous sr ?")) { if (file.delete()) { fileGrid.deleteRow(SmartGrid.row(deleteBtn)); } else { ModalUtil.alert("Suppression impossible", "Impossible de supprimer le fichier " + file.getName()); } } }); fileGrid.add(deleteBtn, 3, rowIndex, null); }
From source file:fruitproject.FruitProject.java
public void second(final String pfname) { final Stage st = new Stage(); Scene scene = null;//from ww w . j av a 2 s. c o m final GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); TableView tv = new TableView(); final TableColumn<Map, String> firstDataColumn = new TableColumn<>("Name"); final TableColumn<Map, String> secondDataColumn = new TableColumn<>("Amount"); final TableColumn<Map, String> thirdDataColumn = new TableColumn<>("Remove"); firstDataColumn.setMinWidth(130); secondDataColumn.setMinWidth(130); thirdDataColumn.setMinWidth(130); if (!pfname.equals("")) { firstDataColumn.setCellValueFactory(new MapValueFactory(Column1MapKey)); secondDataColumn.setCellValueFactory(new MapValueFactory(Column2MapKey)); thirdDataColumn.setCellValueFactory(new MapValueFactory(Column3MapKey)); rows = 0; tv = new TableView<>(generateDataInMap(pfname, addPairs)); } tv.getColumns().setAll(firstDataColumn, secondDataColumn, thirdDataColumn); // secondDataColumn.setCellFactory(TextFieldTableCell.forTableColumn()); ScrollPane sp = new ScrollPane(); sp.setMinWidth(400); sp.setHbarPolicy(ScrollBarPolicy.NEVER); sp.setContent(tv); grid.add(sp, 0, 3); final ComboBox comboBox = new ComboBox(); HBox hb1 = new HBox(); comboBox.setValue("FILE"); comboBox.getItems().addAll("Save this file", "Load a new file"); Button btnOk = new Button(); btnOk.setText("OK"); hb1.getChildren().addAll(comboBox, btnOk); hb1.setSpacing(10); grid.add(hb1, 0, 1); Label label1 = new Label("Title:"); final TextField tfFilename = new TextField(); tfFilename.setText(getTitle(pfname)); HBox hb = new HBox(); hb.getChildren().addAll(label1, tfFilename); hb.setSpacing(10); grid.add(hb, 0, 2); final Stage ps = new Stage(); final TableView tv1 = tv; btnOk.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { //System.out.println("Hello World!"); if (comboBox.getValue().equals("Load a new file")) { first(ps); st.close(); } else { PrintWriter pw = null; try { pw = new PrintWriter("abc.json"); BufferedWriter bw = new BufferedWriter(new FileWriter(pfname, false)); bw.write("{title:\"" + tfFilename.getText() + "\""); bw.write(",fruits:["); for (int i = 0; i < rows; i++) { bw.write("{name:\"" + String.valueOf(firstDataColumn.getCellData(i)) + "\",amount:" + String.valueOf(secondDataColumn.getCellData(i)) + "}"); if (i != rows - 1) bw.write(","); } bw.write("]}"); bw.close(); } catch (Exception e) { System.out.println(e.toString()); } } } }); Button btn = new Button(); btn.setText("New Fruit"); grid.add(btn, 1, 2); // TableView tv=new TableView(); // TableColumn Col1 = new TableColumn("Name"); // TableColumn Col2 = new TableColumn("Amount"); // TableColumn Col3 = new TableColumn("Remove"); // tv.getColumns().addAll(Col1, Col2, Col3); //sp.setFitToWidth(true); Image img = new Image("file:music.jpg"); ImageView iv2 = new ImageView(); iv2.setImage(img); iv2.setFitWidth(200); iv2.setPreserveRatio(true); iv2.setSmooth(true); iv2.setCache(true); grid.add(iv2, 1, 3); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { //System.out.println("Hello World!"); System.out.println(comboBox.valueProperty()); st.close(); third(pfname); } }); scene = new Scene(grid, 700, 450); st.setScene(scene); st.show(); }
From source file:nl.mvdr.umvc3replayanalyser.controller.EditReplayController.java
/** * Updates the assist combo box corresponding to the given character value. * //from www .j av a2 s. c om * @param observable * character observable whose value has changed */ private void updateAssistComboBox(ObservableValue<? extends Umvc3Character> observable) { ComboBox<Assist> comboBox = this.assistComboBoxes.get(observable); if (comboBox == null) { throw new IllegalArgumentException("Unexpected observable: " + observable); } // Character value has changed. Rebuild the contents of the combo box. int index = comboBox.getSelectionModel().getSelectedIndex(); comboBox.getItems().clear(); comboBox.getItems().add(null); for (AssistType type : AssistType.values()) { comboBox.getItems().add(new Assist(type, observable.getValue())); } // Maintain selected index. comboBox.getSelectionModel().select(index); comboBox.setDisable(false); }
From source file:nl.mvdr.umvc3replayanalyser.controller.EditReplayController.java
/** Initialisation method. */ // Default visibility for unit tests. @FXML//from ww w .ja va 2 s . c om void initialize() { log.info("Performing controller initialisation."); // Initialise character combo boxes. for (ComboBox<Umvc3Character> comboBox : Arrays.asList(playerOneCharacterOneComboBox, playerOneCharacterTwoComboBox, playerOneCharacterThreeComboBox, playerTwoCharacterOneComboBox, playerTwoCharacterTwoComboBox, playerTwoCharacterThreeComboBox)) { comboBox.getItems().addAll(Umvc3Character.values()); } // Initialise assist combo boxes. assistComboBoxes = new HashMap<>(); assistComboBoxes.put(playerOneCharacterOneComboBox.valueProperty(), playerOneAssistOneComboBox); assistComboBoxes.put(playerOneCharacterTwoComboBox.valueProperty(), playerOneAssistTwoComboBox); assistComboBoxes.put(playerOneCharacterThreeComboBox.valueProperty(), playerOneAssistThreeComboBox); assistComboBoxes.put(playerTwoCharacterOneComboBox.valueProperty(), playerTwoAssistOneComboBox); assistComboBoxes.put(playerTwoCharacterTwoComboBox.valueProperty(), playerTwoAssistTwoComboBox); assistComboBoxes.put(playerTwoCharacterThreeComboBox.valueProperty(), playerTwoAssistThreeComboBox); // Add a listener, so that whenever a character value is changed, the assist combo box is updated as well. ChangeListener<Umvc3Character> assistListener = new ChangeListener<Umvc3Character>() { /** {@inheritDoc} */ @Override public void changed(ObservableValue<? extends Umvc3Character> observable, Umvc3Character oldValue, Umvc3Character newValue) { if (log.isDebugEnabled()) { log.debug(String.format("Character changed. Old value: %s, new value: %s", oldValue, newValue)); } updateAssistComboBox(observable); } }; playerOneCharacterOneComboBox.valueProperty().addListener(assistListener); playerOneCharacterTwoComboBox.valueProperty().addListener(assistListener); playerOneCharacterThreeComboBox.valueProperty().addListener(assistListener); playerTwoCharacterOneComboBox.valueProperty().addListener(assistListener); playerTwoCharacterTwoComboBox.valueProperty().addListener(assistListener); playerTwoCharacterThreeComboBox.valueProperty().addListener(assistListener); // Add another listener to ensure the OK button is enabled when the required fields have been filled in. ChangeListener<Object> okEnabledListener = new ChangeListener<Object>() { /** {@inheritDoc} */ @Override public void changed(ObservableValue<? extends Object> observable, Object oldValue, Object newValue) { if (log.isDebugEnabled()) { log.debug(String.format("Observable value changed. Old value: %s, new value: %s", oldValue, newValue)); } okButton.setDisable(!isFilledIn()); } }; playerOneTextField.textProperty().addListener(okEnabledListener); playerTwoTextField.textProperty().addListener(okEnabledListener); playerOneCharacterOneComboBox.valueProperty().addListener(okEnabledListener); playerOneCharacterTwoComboBox.valueProperty().addListener(okEnabledListener); playerOneCharacterThreeComboBox.valueProperty().addListener(okEnabledListener); playerTwoCharacterOneComboBox.valueProperty().addListener(okEnabledListener); playerTwoCharacterTwoComboBox.valueProperty().addListener(okEnabledListener); playerTwoCharacterThreeComboBox.valueProperty().addListener(okEnabledListener); // Set the value of all fields based on the contents of defaultContents if available. // Do this after registering the listeners, so that when a character value is set, the assist combo box is // updated, and the status of the OK button is updated at the end. // Always update the assist value after the corresponding character value. if (defaultContents != null) { playerOneTextField.setText(defaultContents.getPlayerOne().getGamertag()); playerTwoTextField.setText(defaultContents.getPlayerTwo().getGamertag()); Team teamOne = defaultContents.getTeamOne(); Team teamTwo = defaultContents.getTeamTwo(); playerOneCharacterOneComboBox.setValue(teamOne.getFirstCharacter()); playerOneAssistOneComboBox.setValue(teamOne.getFirstAssist()); playerOneCharacterTwoComboBox.setValue(teamOne.getSecondCharacter()); playerOneAssistTwoComboBox.setValue(teamOne.getSecondAssist()); playerOneCharacterThreeComboBox.setValue(teamOne.getThirdCharacter()); playerOneAssistThreeComboBox.setValue(teamOne.getThirdAssist()); playerTwoCharacterOneComboBox.setValue(teamTwo.getFirstCharacter()); playerTwoAssistOneComboBox.setValue(teamTwo.getFirstAssist()); playerTwoCharacterTwoComboBox.setValue(teamTwo.getSecondCharacter()); playerTwoAssistTwoComboBox.setValue(teamTwo.getSecondAssist()); playerTwoCharacterThreeComboBox.setValue(teamTwo.getThirdCharacter()); playerTwoAssistThreeComboBox.setValue(teamTwo.getThirdAssist()); } log.info("Initialisation complete."); }
From source file:account.management.controller.NewVoucherController.java
@FXML private void onSelectType(ActionEvent event) { filter_acc = FXCollections.observableArrayList(); for (int i = 0; i < this.account_list.size(); i++) { if (this.account_list.get(i).getAccount_type() .equals(this.select_type.getSelectionModel().getSelectedItem().getId()) && this.account_list.get(i).getId() > 57) { filter_acc.add(this.account_list.get(i)); }/*from w w w .j a v a 2s .co m*/ } //this.account_list.clear(); for (int i = 0; i < this.field_container.getChildren().size(); i++) { HBox row = (HBox) this.field_container.getChildren().get(i); ComboBox<Account> combo = (ComboBox<Account>) row.getChildren().get(0); combo.getItems().clear(); combo.getItems().addAll(filter_acc); } }
From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java
/** * Creates the toolBar for the editor.//from w w w . j av a 2 s. c o m * * @return */ private ToolBar createToolBar() { ToolBar toolBar = new ToolBar(); toolBar.setOrientation(Orientation.HORIZONTAL); Button btnSave = GlyphsDude.createIconButton(MaterialDesignIcon.FLOPPY, "Save"); btnSave.setOnAction(this::handleSaveButton); Button btnExportSTL = GlyphsDude.createIconButton(MaterialDesignIcon.EXPORT, "Export STL"); btnExportSTL.setOnAction(this::handleExportAsStlFile); Button btnExportPNG = GlyphsDude.createIconButton(MaterialDesignIcon.CAMERA, "Export PNG"); btnExportPNG.setOnAction(this::handleExportAsPngFile); Button btnRun = GlyphsDude.createIconButton(MaterialDesignIcon.RUN, "Run"); btnRun.setOnAction(this::handleCompileAndRun); ToggleButton btnAutoCompile = GlyphsDude.createIconToggleButton(MaterialDesignIcon.AUTO_FIX, "Automatic run", null, ContentDisplay.LEFT); btnAutoCompile.setSelected(false); ToggleButton btn3DNav = GlyphsDude.createIconToggleButton(MaterialDesignIcon.ROTATE_3D, "3D Navigation ", null, ContentDisplay.LEFT); btn3DNav.setSelected(false); ComboBox cbxSourceExamples = new ComboBox(); cbxSourceExamples.getItems().addAll("BatteryHolder", "BoardMount", "BreadBoardConnector", "ServoMount", "Wheel"); this.cbxSourceExamples = cbxSourceExamples; // TODO: maybe cleaner way // to do this ? Button btnPasteSource = GlyphsDude.createIconButton(MaterialDesignIcon.CONTENT_PASTE, "Paste source"); btnPasteSource.setOnAction(this::handlePasteSource); toolBar.getItems().addAll(btnSave, btnExportSTL, btnExportPNG, new Separator(), btnRun, new Separator(), btnAutoCompile, new Separator(), cbxSourceExamples, btnPasteSource); return toolBar; }
From source file:account.management.controller.NewVoucherController.java
@FXML private void onAddNewFieldButtonClick(ActionEvent event) { HBox row = new HBox(); row.setId("field_row"); ComboBox<Account> select_account = new ComboBox<>(); if (this.select_type.getSelectionModel().isEmpty()) { select_account.getItems().addAll(this.account_list); } else {// w w w. j ava 2 s . c o m select_account.getItems().addAll(this.filter_acc); } TextField dr = new TextField(); TextField cr = new TextField(); TextField remarks = new TextField(); Button del_row = new Button("Delete"); row.setSpacing(field_row.getSpacing()); ComboBox<Account> combo = (ComboBox) field_row.getChildren().get(0); select_account.setPrefWidth(combo.getPrefWidth()); select_account.setPromptText("Select account"); TextField tf = (TextField) field_row.getChildren().get(1); dr.setPrefWidth(tf.getPrefWidth()); dr.setPromptText("Dr"); tf = (TextField) field_row.getChildren().get(2); cr.setPrefWidth(tf.getPrefWidth()); cr.setPromptText("Cr"); tf = (TextField) field_row.getChildren().get(3); remarks.setPrefWidth(tf.getPrefWidth()); remarks.setPromptText("remarks"); row.getChildren().addAll(select_account, dr, cr, remarks, del_row); field_container.getChildren().add(row); del_row.setOnMouseClicked((MouseEvent event1) -> { field_container.getChildren().removeAll(row); validateFields(); }); combo.setOnAction((e) -> { if (!combo.getSelectionModel().isEmpty() && combo.getSelectionModel().getSelectedItem().getId() == 21) { combo.setPromptText("Select Party"); combo.getItems().clear(); combo.getItems().addAll(this.filter_party_rec); } if (!combo.getSelectionModel().isEmpty() && combo.getSelectionModel().getSelectedItem().getId() == 34) { combo.getItems().clear(); combo.getItems().addAll(this.filter_party_pay); combo.setPromptText("Select Party"); } }); new AutoCompleteComboBoxListener<>(select_account); select_account.setOnHiding((e) -> { Account a = select_account.getSelectionModel().getSelectedItem(); select_account.setEditable(false); select_account.getSelectionModel().select(a); }); select_account.setOnShowing((e) -> { select_account.setEditable(true); }); validateFields(); }