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

The following examples show how to use javafx.scene.control.ComboBox#setOnKeyReleased() . 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: 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 2
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 3
Source File: PVTable.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void startEdit()
{
    super.startEdit();
    if (! isEditing())
        return;

    setText(null);

    final TableItemProxy proxy = getTableView().getItems().get(getIndex());
    final VType value = proxy.getItem().getValue();
    if (value instanceof VEnum)
    {
        // Use combo for Enum-valued data
        final VEnum enumerated = (VEnum) value;
        final ComboBox<String> combo = new ComboBox<>();
        combo.getItems().addAll(enumerated.getDisplay().getChoices());
        combo.getSelectionModel().select(enumerated.getIndex());

        combo.setOnAction(event ->
        {
            // Need to write String, using the enum index
            commitEdit(Integer.toString(combo.getSelectionModel().getSelectedIndex()));
            event.consume();
        });
        combo.setOnKeyReleased(event ->
        {
            if (event.getCode() == KeyCode.ESCAPE)
            {
                cancelEdit();
                event.consume();
            }
        });
        setGraphic(combo);
        Platform.runLater(() -> combo.requestFocus());
        Platform.runLater(() -> combo.show());
    }
    else
    {
        final TextField text_field = new TextField(getItem());
        text_field.setOnAction(event ->
        {
            commitEdit(text_field.getText());
            event.consume();
        });
        text_field.setOnKeyReleased(event ->
        {
            if (event.getCode() == KeyCode.ESCAPE)
            {
                cancelEdit();
                event.consume();
            }
        });
        setGraphic(text_field);
        text_field.selectAll();
        text_field.requestFocus();
    }
}