List of usage examples for javafx.scene.control ComboBox getSelectionModel
public final SingleSelectionModel<T> getSelectionModel()
From source file:Main.java
public static String getComboBoxStringValue(ComboBox<String> comboBox) { return comboBox.getValue() == null ? comboBox.getPromptText() : comboBox.getSelectionModel().getSelectedItem(); }
From source file:Main.java
public static Integer getComboBoxIntegerValue(ComboBox<String> comboBox) { return comboBox.getValue() == null ? Integer.valueOf(comboBox.getPromptText()) : Integer.valueOf(comboBox.getSelectionModel().getSelectedItem()); }
From source file:cz.lbenda.rcp.DialogHelper.java
/** Open dialog with chooser when user can choose single option * @param question question which is show to user * @param items list of items which user can choose * @param <T> type of item//w w w. j a v a2 s .c o m * @return null if user click on cancel or don't choose anything, elsewhere choosed item */ @SuppressWarnings("unchecked") public static <T> T chooseSingOption(String question, T... items) { if (items.length == 0) { return null; } Dialog<T> dialog = new Dialog<>(); dialog.setResizable(false); dialog.setTitle(chooseSingleOption_title); dialog.setHeaderText(question); ComboBox<T> comboBox = new ComboBox<>(); comboBox.getItems().addAll(items); dialog.getDialogPane().setContent(comboBox); ButtonType btCancel = ButtonType.CANCEL; ButtonType btOk = ButtonType.OK; dialog.getDialogPane().getButtonTypes().addAll(btCancel, btOk); Optional<T> result = dialog.showAndWait(); if (result.isPresent()) { if (btCancel == result.get()) { return null; } if (btOk == result.get()) { return comboBox.getSelectionModel().getSelectedItem(); } } else { return null; } return result.get(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group(), 450, 250); ObservableList<String> list = FXCollections.observableArrayList("1", "2", "3", "4"); ComboBox<String> emailComboBox = new ComboBox<String>(list); emailComboBox.setValue("A"); System.out.println(emailComboBox.getSelectionModel().getSelectedIndex()); GridPane grid = new GridPane(); grid.setVgap(4);// w w w . java 2 s. c o m 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:mesclasses.controller.PageController.java
public void checkMandatory(ComboBox box) { if (box.getSelectionModel().getSelectedItem() == null) { addMissingError(box);//w w w. j ava 2 s . c om } else { removeMissingError(box); } }
From source file:org.pdfsam.split.SplitAfterPredefinedSetOfPagesRadioButton.java
public SplitAfterPredefinedSetOfPagesRadioButton(ComboBox<KeyStringValueItem<PredefinedSetOfPages>> combo) { super(DefaultI18nContext.getInstance().i18n("Split after")); this.combo = combo; combo.getSelectionModel().selectFirst(); setTooltip(new Tooltip( DefaultI18nContext.getInstance().i18n("Split the document after the given page numbers"))); }
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:account.management.controller.inventory.InsertStockController.java
@FXML private void onSaveButtonClick(ActionEvent event) { this.save.setDisable(true); try {/* ww w. j a v a 2s . c o m*/ String date = new SimpleDateFormat("yyyy-MM-dd") .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.date.getValue().toString())); JSONArray array = new JSONArray(); for (int i = 0; i < this.conatiner.getChildren().size(); i++) { HBox row = (HBox) this.conatiner.getChildren().get(i); ComboBox<Product> item = (ComboBox) row.getChildren().get(0); TextField qty = (TextField) row.getChildren().get(1); TextField rate = (TextField) row.getChildren().get(2); JSONObject obj = new JSONObject(); obj.put("id", item.getSelectionModel().getSelectedItem().getId()); obj.put("quantity", qty.getText()); obj.put("rate", rate.getText()); array.put(obj); } Unirest.post(MetaData.baseUrl + "products/ledger") .field("voucher_type", this.voucher_type.getSelectionModel().getSelectedItem()) .field("date", date).field("products", array).asString(); Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setHeaderText(null); alert.setContentText("Ledger has been saved successfully!"); alert.setGraphic(new ImageView(new Image("resources/success.jpg"))); alert.showAndWait(); this.save.setDisable(false); } catch (Exception ex) { Logger.getLogger(InsertStockController.class.getName()).log(Level.SEVERE, null, ex); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setHeaderText(null); alert.setContentText("Sorry!! there is an error. Please try again."); alert.setGraphic(new ImageView(new Image("resources/error.jpg"))); alert.showAndWait(); } }
From source file:account.management.controller.inventory.InsertStockController.java
public void addRow() { ComboBox<Product> select_item = new ComboBox(); select_item.setPromptText("Select Item"); select_item.setPrefWidth(190);/* w w w . j av a 2 s .c o m*/ select_item.setPrefHeight(25); new AutoCompleteComboBoxListener<>(select_item); select_item.setOnHiding((e) -> { Product a = select_item.getSelectionModel().getSelectedItem(); select_item.setEditable(false); select_item.getSelectionModel().select(a); }); select_item.setOnShowing((e) -> { select_item.setEditable(true); }); TextField qty = new TextField(); qty.setPromptText("Quantity"); qty.setPrefWidth(97); qty.setPrefHeight(25); TextField rate = new TextField(); rate.setPrefWidth(100); rate.setPrefHeight(25); if (this.voucher_type.getSelectionModel().getSelectedItem().equals("Purchase")) { rate.setPromptText("Purchase Rate"); } else { rate.setPromptText("Sell Rate"); } Button del = new Button("Delete"); HBox row = new HBox(); row.getChildren().addAll(select_item, qty, rate, del); row.setSpacing(10); row.setPadding(new Insets(0, 0, 0, 15)); this.conatiner.getChildren().add(row); del.setOnAction((e) -> { this.conatiner.getChildren().remove(row); this.add_row.setDisable(false); calculateTotal(); }); select_item.getItems().addAll(this.products_list); select_item.setOnAction((e) -> { qty.setText("0"); if (this.voucher_type.getSelectionModel().getSelectedItem().equals("Purchase")) { rate.setText(String.valueOf(select_item.getSelectionModel().getSelectedItem().getLast_p_rate())); } else { rate.setText(String.valueOf(select_item.getSelectionModel().getSelectedItem().getLast_s_rate())); } calculateTotal(); }); qty.setOnKeyReleased((e) -> { calculateTotal(); }); rate.setOnKeyReleased((e) -> { calculateTotal(); }); if (this.conatiner.getChildren().size() >= 8) { this.add_row.setDisable(true); return; } }
From source file:nl.mvdr.umvc3replayanalyser.controller.EditReplayController.java
/** * Updates the assist combo box corresponding to the given character value. * /* w w w. j a v a 2s .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); }