Java Code Examples for javafx.scene.control.ComboBox#setItems()

The following examples show how to use javafx.scene.control.ComboBox#setItems() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComboBoxSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ComboBoxSample() {

        HBox hbox = HBoxBuilder.create().alignment(Pos.CENTER).spacing(15).build();
               
        //Non-editable combobox. Created with a builder
        ComboBox uneditableComboBox = ComboBoxBuilder.create()
                .id("uneditable-combobox")
                .promptText("Make a choice...")
                .items(FXCollections.observableArrayList(strings.subList(0, 8))).build();

        //Editable combobox. Use the default item display length
        ComboBox<String> editableComboBox = new ComboBox<String>();
        editableComboBox.setId("second-editable");
        editableComboBox.setPromptText("Edit or Choose...");
        editableComboBox.setItems(strings);
        editableComboBox.setEditable(true);

        hbox.getChildren().addAll(uneditableComboBox, editableComboBox);
        getChildren().add(hbox);
    }
 
Example 2
Source File: ComboBoxSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ComboBoxSample() {

        HBox hbox = HBoxBuilder.create().alignment(Pos.CENTER).spacing(15).build();
               
        //Non-editable combobox. Created with a builder
        ComboBox uneditableComboBox = ComboBoxBuilder.create()
                .id("uneditable-combobox")
                .promptText("Make a choice...")
                .items(FXCollections.observableArrayList(strings.subList(0, 8))).build();

        //Editable combobox. Use the default item display length
        ComboBox<String> editableComboBox = new ComboBox<String>();
        editableComboBox.setId("second-editable");
        editableComboBox.setPromptText("Edit or Choose...");
        editableComboBox.setItems(strings);
        editableComboBox.setEditable(true);

        hbox.getChildren().addAll(uneditableComboBox, editableComboBox);
        getChildren().add(hbox);
    }
 
Example 3
Source File: CardEditor.java    From metastone with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void fillWithSpells(ComboBox<Class<? extends Spell>> comboBox) {
	ObservableList<Class<? extends Spell>> items = FXCollections.observableArrayList();
	String spellPath = "./src/main/java/" + Spell.class.getPackage().getName().replace(".", "/") + "/";
	for (File file : FileUtils.listFiles(new File(spellPath), new String[] { "java" }, false)) {
		String fileName = file.getName().replace(".java", "");
		String spellClassName = Spell.class.getPackage().getName() + "." + fileName;
		Class<? extends Spell> spellClass = null;
		try {
			spellClass = (Class<? extends Spell>) Class.forName(spellClassName);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}

		items.add(spellClass);
	}
	comboBox.setItems(items);
	comboBox.setOnKeyReleased(new ComboBoxKeyHandler<Class<? extends Spell>>(comboBox));

}
 
Example 4
Source File: EditorMainWindow.java    From metastone with GNU General Public License v2.0 6 votes vote down vote up
private void setupAttributeBoxes() {
	for (ComboBox<Attribute> comboBox : attributeBoxes) {
		ObservableList<Attribute> items = FXCollections.observableArrayList();
		items.addAll(Attribute.values());
		Collections.sort(items, (obj1, obj2) -> {
			if (obj1 == obj2) {
				return 0;
			}
			if (obj1 == null) {
				return -1;
			}
			if (obj2 == null) {
				return 1;
			}
			return obj1.toString().compareTo(obj2.toString());
		});
		comboBox.setItems(items);
		comboBox.valueProperty().addListener((ov, oldValue, newValue) -> onAttributesChanged());
		comboBox.setOnKeyReleased(new ComboBoxKeyHandler<Attribute>(comboBox));
	}
	for (TextField attributeField : attributeFields) {
		attributeField.textProperty().addListener((ov, oldValue, newValue) -> onAttributesChanged());
	}
}
 
Example 5
Source File: DebugView.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private void addGroup(String title, ObservableList<Class<? extends Task>> list) {
    final Tuple2<Label, ComboBox<Class<? extends Task>>> selectTaskToIntercept =
            addTopLabelComboBox(root, ++rowIndex, title, "Select task to intercept", 15);
    ComboBox<Class<? extends Task>> comboBox = selectTaskToIntercept.second;
    comboBox.setVisibleRowCount(list.size());
    comboBox.setItems(list);
    comboBox.setConverter(new StringConverter<>() {
        @Override
        public String toString(Class<? extends Task> item) {
            return item.getSimpleName();
        }

        @Override
        public Class<? extends Task> fromString(String s) {
            return null;
        }
    });
    comboBox.setOnAction(event -> Task.taskToIntercept = comboBox.getSelectionModel().getSelectedItem());
}
 
Example 6
Source File: SelectableTitledPaneDemo.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override 
	public void start(Stage stage) {
	        
		  List<String> list = new ArrayList<>(Arrays.asList(strs));
		  	  
//		  ComboBox<?> combo = ComboBoxBuilder.create().
//		            prefWidth(150).
//		            //items(list).
//		            items(FXCollections.observableArrayList(list)).//"aa", "bb", "bb")); 		  
//		            //promptText(resourceBundle.getString("search.prompt.owner")).
//		            promptText("Choice").
//		            build();
		 
		  ComboBox<String> combo = new ComboBox<String>();
		  combo.setItems(FXCollections.observableArrayList(list));
		  combo.setPrefWidth(150);
		  combo.setPromptText("Choice");

		  //combo.setItems((ObservableList<?>) FXCollections.observableArrayList(list));//"aa", "bb", "bb"));
		  
		  
		  SelectableTitledPane ownerParams = new SelectableTitledPane(
				  //resourceBundle.getString("search.checkbox.owner"),
				  "checkbox",
				  combo);

	        
	        StackPane pane = new StackPane();
	        pane.setBackground(null);
	        pane.setPadding(new Insets(10, 10, 10, 10));
	        pane.getChildren().addAll( ownerParams);

	        Scene scene = new Scene(pane);
	        stage.setScene(scene);
	        stage.show();
	    }
 
Example 7
Source File: GUIUtil.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Tuple2<ComboBox<TradeCurrency>, Integer> addRegionCountryTradeCurrencyComboBoxes(GridPane gridPane,
                                                                                               int gridRow,
                                                                                               Consumer<Country> onCountrySelectedHandler,
                                                                                               Consumer<TradeCurrency> onTradeCurrencySelectedHandler) {
    gridRow = addRegionCountry(gridPane, gridRow, onCountrySelectedHandler);

    ComboBox<TradeCurrency> currencyComboBox = FormBuilder.addComboBox(gridPane, ++gridRow,
            Res.get("shared.currency"));
    currencyComboBox.setPromptText(Res.get("list.currency.select"));
    currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getAllSortedFiatCurrencies()));

    currencyComboBox.setConverter(new StringConverter<>() {
        @Override
        public String toString(TradeCurrency currency) {
            return currency.getNameAndCode();
        }

        @Override
        public TradeCurrency fromString(String string) {
            return null;
        }
    });
    currencyComboBox.setDisable(true);

    currencyComboBox.setOnAction(e ->
            onTradeCurrencySelectedHandler.accept(currencyComboBox.getSelectionModel().getSelectedItem()));

    return new Tuple2<>(currencyComboBox, gridRow);
}
 
Example 8
Source File: RevolutForm.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;

    // country selection is added only to prevent anymore email id input and
    // solely to validate the given phone number
    ComboBox<Country> countryComboBox = addCountrySelection();
    setCountryComboBoxAction(countryComboBox);
    countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllRevolutCountries()));

    accountIdInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.revolut.phoneNr"));
    accountIdInputTextField.setValidator(validator);
    accountIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        account.setAccountId(newValue.trim());
        updateFromInputs();
    });

    addCurrenciesGrid(true);
    addLimitations(false);
    addAccountNameTextFieldWithAutoFillToggleButton();

    //set default country as selected
    selectedCountry = CountryUtil.getDefaultCountry();
    if (CountryUtil.getAllRevolutCountries().contains(selectedCountry)) {
        countryComboBox.getSelectionModel().select(selectedCountry);
    }
}
 
Example 9
Source File: MetadataOverview.java    From sis with Apache License 2.0 5 votes vote down vote up
private ComboBox<String> createComboBox(final Map<String, Identification> m) {
    ComboBox<String> cb = new ComboBox<>();
    Collection<? extends Identification> ids = this.metadata.getIdentificationInfo();
    ObservableList<String> options = FXCollections.observableArrayList();
    int i = 1;
    if (ids.size() > 1) {
        for (Identification id : ids) {
            String currentName;
            if (id.getCitation() != null) {
                currentName = id.getCitation().getTitle().toString();
            } else {
                currentName = Integer.toString(i);
            }
            options.add(currentName);
            m.put(currentName, id);
        }
        cb.setItems(options);
        cb.setValue(ids.iterator().next().getCitation().getTitle().toString());
    } else if (ids.size() == 1) {
        if (ids.iterator().next().getCitation() != null) {
            m.put(ids.iterator().next().getCitation().getTitle().toString(), ids.iterator().next());
            cb.setValue(ids.iterator().next().getCitation().getTitle().toString());
            cb.setVisible(false);
        }
    } else {
        cb.setValue("No data to show");
        cb.setVisible(false);
    }
    return cb;
}
 
Example 10
Source File: FXMLResultOutputController.java    From pikatimer with GNU General Public License v3.0 4 votes vote down vote up
private void showRaceReportOutputTarget(RaceOutputTarget t){
        HBox rotHBox = new HBox();
        rotHBox.setSpacing(4);
        ComboBox<ReportDestination> destinationChoiceBox = new ComboBox();
        
        //destinationChoiceBox.getItems().setAll(resultsDAO.listReportDestinations());
        
        destinationChoiceBox.setItems(resultsDAO.listReportDestinations());
        
        // ChoserBox for the OutputDestination
        destinationChoiceBox.getSelectionModel().selectedIndexProperty().addListener((ObservableValue<? extends Number> observableValue, Number number, Number number2) -> {
            if (t.getID() < 0) return; // deleted
            
            ReportDestination op = destinationChoiceBox.getItems().get((Integer) number2);
//            if(! Objects.equals(destinationChoiceBox.getSelectionModel().getSelectedItem(),op)) {
//                t.setOutputDestination(op.getID());
//                resultsDAO.saveRaceReportOutputTarget(t);
//            }
            t.setOutputDestination(op.getID());
            resultsDAO.saveRaceReportOutputTarget(t);
        });
        
        if (t.outputDestination() == null) destinationChoiceBox.getSelectionModel().selectFirst();
        else destinationChoiceBox.getSelectionModel().select(t.outputDestination());
        destinationChoiceBox.setPrefWidth(150);
        destinationChoiceBox.setMaxWidth(150);
        
        // TextField for the filename
        TextField filename = new TextField();
        filename.setText(t.getOutputFilename());
        filename.setPrefWidth(200);
        filename.setMaxWidth(400);
        
        filename.textProperty().addListener((observable, oldValue, newValue) -> {
            t.setOutputFilename(newValue);
            resultsDAO.saveRaceReportOutputTarget(t);    
        });
        
        // Remove 
        
        Button remove = new Button("Remove");
        remove.setOnAction((ActionEvent e) -> {
            removeRaceReportOutputTarget(t);
        });
        
        rotHBox.getChildren().addAll(destinationChoiceBox,filename,remove);
        // Add the rotVBox to the outputTargetsVBox
        rotHBoxMap.put(t, rotHBox);
        outputTargetsVBox.getChildren().add(rotHBox);
       
    }
 
Example 11
Source File: FeatureLayerExtrusionSample.java    From arcgis-runtime-samples-java with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) {

  StackPane stackPane = new StackPane();
  Scene fxScene = new Scene(stackPane);
  // for adding styling to any controls that are added
  fxScene.getStylesheets().add(getClass().getResource("/feature_layer_extrusion/style.css").toExternalForm());

  // set title, size, and add scene to stage
  stage.setTitle("Feature Layer Extrusion Sample");
  stage.setWidth(800);
  stage.setHeight(700);
  stage.setScene(fxScene);
  stage.show();

  // so scene can be visible within application
  ArcGISScene scene = new ArcGISScene(Basemap.createTopographic());
  sceneView = new SceneView();
  sceneView.setArcGISScene(scene);
  stackPane.getChildren().add(sceneView);

  // get us census data as a service feature table
  ServiceFeatureTable statesServiceFeatureTable = new ServiceFeatureTable("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3");

  // creates feature layer from table and add to scene
  final FeatureLayer statesFeatureLayer = new FeatureLayer(statesServiceFeatureTable);
  // feature layer must be rendered dynamically for extrusion to work
  statesFeatureLayer.setRenderingMode(FeatureLayer.RenderingMode.DYNAMIC);
  scene.getOperationalLayers().add(statesFeatureLayer);

  // symbols are used to display features (US states) from table
  SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF000000, 1.0f);
  SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0xFF0000FF, lineSymbol);
  final SimpleRenderer renderer = new SimpleRenderer(fillSymbol);
  // set the extrusion mode to absolute height
  renderer.getSceneProperties().setExtrusionMode(Renderer.SceneProperties.ExtrusionMode.ABSOLUTE_HEIGHT);
  statesFeatureLayer.setRenderer(renderer);

  // set camera to focus on state features
  Point lookAtPoint = new Point(-10974490, 4814376, 0, SpatialReferences.getWebMercator());
  sceneView.setViewpointCamera(new Camera(lookAtPoint, 10000000, 0, 20, 0));

  // create a combo box to choose between different expressions/attributes to extrude by
  ComboBox<ExtrusionAttribute> attributeComboBox = new ComboBox<>();
  attributeComboBox.setCellFactory(list -> new ListCell<ExtrusionAttribute> (){
    @Override
    protected void updateItem(ExtrusionAttribute attribute, boolean bln) {

      super.updateItem(attribute, bln);
      if (attribute != null) {
        setText(attribute.getName());
      }
    }
  });
  attributeComboBox.setConverter(new StringConverter<ExtrusionAttribute>() {

    @Override
    public String toString(ExtrusionAttribute travelMode) {
      return travelMode != null ? travelMode.getName() : "";
    }

    @Override
    public ExtrusionAttribute fromString(String fileName) {
      return null;
    }
  });
  // scale down outlier populations
  ExtrusionAttribute populationDensity = new ExtrusionAttribute("Population Density","[POP07_SQMI] * 5000 + 100000");
  // scale up density
  ExtrusionAttribute totalPopulation = new ExtrusionAttribute("Total Population", "[POP2007]/ 10");
  attributeComboBox.setItems(FXCollections.observableArrayList(populationDensity, totalPopulation));
  stackPane.getChildren().add(attributeComboBox);
  StackPane.setAlignment(attributeComboBox, Pos.TOP_LEFT);
  StackPane.setMargin(attributeComboBox, new Insets(10, 0, 0, 10));

  // set the extrusion expression on the renderer when one is chosen in the combo box
  attributeComboBox.getSelectionModel().selectedItemProperty().addListener(e -> {
    ExtrusionAttribute selectedAttribute = attributeComboBox.getSelectionModel().getSelectedItem();
    renderer.getSceneProperties().setExtrusionExpression(selectedAttribute.getExpression());
  });

  // start with total population selected
  attributeComboBox.getSelectionModel().select(totalPopulation);
}
 
Example 12
Source File: SepaInstantForm.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;

    InputTextField holderNameInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow,
            Res.get("payment.account.owner"));
    holderNameInputTextField.setValidator(inputValidator);
    holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        sepaInstantAccount.setHolderName(newValue);
        updateFromInputs();
    });

    ibanInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, IBAN);
    ibanInputTextField.setTextFormatter(new TextFormatter<>(new IBANNormalizer()));
    ibanInputTextField.setValidator(ibanValidator);
    ibanInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        sepaInstantAccount.setIban(newValue);
        updateFromInputs();

    });
    InputTextField bicInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, BIC);
    bicInputTextField.setValidator(bicValidator);
    bicInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        sepaInstantAccount.setBic(newValue);
        updateFromInputs();

    });

    ComboBox<Country> countryComboBox = addCountrySelection();

    setCountryComboBoxAction(countryComboBox, sepaInstantAccount);

    addEuroCountriesGrid();
    addNonEuroCountriesGrid();
    addLimitations(false);
    addAccountNameTextFieldWithAutoFillToggleButton();

    countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllSepaInstantCountries()));
    Country country = CountryUtil.getDefaultCountry();
    if (CountryUtil.getAllSepaInstantCountries().contains(country)) {
        countryComboBox.getSelectionModel().select(country);
        sepaInstantAccount.setCountry(country);
    }

    updateFromInputs();
}
 
Example 13
Source File: SepaForm.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;

    InputTextField holderNameInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow,
            Res.get("payment.account.owner"));
    holderNameInputTextField.setValidator(inputValidator);
    holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        sepaAccount.setHolderName(newValue);
        updateFromInputs();
    });

    ibanInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, IBAN);
    ibanInputTextField.setTextFormatter(new TextFormatter<>(new IBANNormalizer()));
    ibanInputTextField.setValidator(ibanValidator);
    ibanInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        sepaAccount.setIban(newValue);
        updateFromInputs();

    });
    InputTextField bicInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, BIC);
    bicInputTextField.setValidator(bicValidator);
    bicInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        sepaAccount.setBic(newValue);
        updateFromInputs();

    });

    ComboBox<Country> countryComboBox = addCountrySelection();

    setCountryComboBoxAction(countryComboBox, sepaAccount);

    addEuroCountriesGrid();
    addNonEuroCountriesGrid();
    addLimitations(false);
    addAccountNameTextFieldWithAutoFillToggleButton();

    countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllSepaCountries()));
    Country country = CountryUtil.getDefaultCountry();
    if (CountryUtil.getAllSepaCountries().contains(country)) {
        countryComboBox.getSelectionModel().select(country);
        sepaAccount.setCountry(country);
    }

    updateFromInputs();
}
 
Example 14
Source File: BackSpace.java    From JavaFX with MIT License 4 votes vote down vote up
@Override
public void start(Stage stage) {
	stage.setTitle("ComboBox");

	// non-editable column
	VBox nonEditBox = new VBox(15);

	ComboBox comboBox1 = new ComboBox();
	comboBox1.setEditable(true);
	comboBox1.setItems(FXCollections.observableArrayList(strings.subList(0,
			4)));
	comboBox1.sceneProperty().addListener(new InvalidationListener() {

		@Override
		public void invalidated(Observable arg0) {
			System.out.println("sceneProperty changed!");
		}
	});

	nonEditBox.getChildren().add(comboBox1);

	ComboBox comboBox2 = new ComboBox();
	comboBox2.setEditable(true);
	comboBox2.setItems(FXCollections.observableArrayList(strings.subList(0,
			5)));
	nonEditBox.getChildren().add(comboBox2);

	TextField textField1 = new TextField();
	nonEditBox.getChildren().add(textField1);

	nonEditBox.addEventHandler(KeyEvent.ANY, new EventHandler<KeyEvent>() {

		@Override
		public void handle(KeyEvent keyEvent) {
			if (keyEvent.getCode().equals(KeyCode.BACK_SPACE)
					|| keyEvent.getCode().equals(KeyCode.DELETE)) {
				System.out.println("VBox is receiving key event !");
			}
		}
	});

	HBox vbox = new HBox(20);
	vbox.setLayoutX(40);
	vbox.setLayoutY(25);

	vbox.getChildren().addAll(nonEditBox);
	Scene scene = new Scene(new Group(vbox), 620, 190);

	stage.setScene(scene);
	stage.show();

	// scene.impl_focusOwnerProperty().addListener(new
	// ChangeListener<Node>() {
	// public void changed(ObservableValue<? extends Node> ov, Node t, Node
	// t1) {
	// System.out.println("focus moved from " + t + " to " + t1);
	// }
	// });
}