package comboboxapp1; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.Event; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; /** * @author Alexander Kirov */ public class Issue4 extends Application { public static void main(String[] args) { launch(args); } final ComboBox testedComboBox = new ComboBox(); static int counter = 0; @Override public void start(Stage stage) throws Exception { VBox pane = new VBox(); pane.setPrefHeight(200); pane.setPrefWidth(200); testedComboBox.setEditable(true); testedComboBox.setPrefWidth(150); testedComboBox.getItems().addAll("1", "2", "3"); VBox vb = new VBox(); Button applyCustomStringConverter = ButtonBuilder.create().text("Apply custom string converter").build(); applyCustomStringConverter.setOnAction(new EventHandler() { public void handle(ActionEvent t) { testedComboBox.setConverter(new CustomStringConverter()); } }); pane.getChildren().addAll(testedComboBox, applyCustomStringConverter, getAddItemHBox()); vb.getChildren().addAll(pane); Scene scene = new Scene(vb, 400, 400); stage.setScene(scene); stage.show(); } private HBox getAddItemHBox() { HBox hb = new HBox(); Label lb = new Label("Add item"); final TextField tf = TextFieldBuilder.create().prefWidth(50).build(); Label atLb = new Label("at pos"); final TextField tfPos = TextFieldBuilder.create().prefWidth(50).build(); Button bt = ButtonBuilder.create().text("Add!").build(); bt.setOnAction(new EventHandler() { public void handle(Event t) { int index = Integer.parseInt(tfPos.getText()); ((ComboBox) testedComboBox).getItems().add(index, tf.getText()); } }); hb.getChildren().addAll(lb, tf, atLb, tfPos, bt); return hb; } }