當前位置: 首頁>>代碼示例>>Java>>正文


Java StringConverter類代碼示例

本文整理匯總了Java中javafx.util.StringConverter的典型用法代碼示例。如果您正苦於以下問題:Java StringConverter類的具體用法?Java StringConverter怎麽用?Java StringConverter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StringConverter類屬於javafx.util包,在下文中一共展示了StringConverter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createTextField

import javafx.util.StringConverter; //導入依賴的package包/類
static <T> TextField createTextField(final Cell<T> cell, final StringConverter<T> converter) {
    final TextField textField = new TextField(getItemText(cell, converter));

    // Use onAction here rather than onKeyReleased (with check for Enter),
    // as otherwise we encounter RT-34685
    textField.setOnAction(event -> {
        if (converter == null) {
            throw new IllegalStateException(
                    "Attempting to convert text input into Object, but provided "
                    + "StringConverter is null. Be sure to set a StringConverter "
                    + "in your cell factory.");
        }
        cell.commitEdit(converter.fromString(textField.getText()));
        event.consume();
    });
    textField.setOnKeyReleased(t -> {
        if (t.getCode() == KeyCode.ESCAPE) {
            cell.cancelEdit();
            t.consume();
        }
    });
    return textField;
}
 
開發者ID:Naoghuman,項目名稱:ABC-List,代碼行數:24,代碼來源:CellUtils.java

示例2: initializeExpressionsSortFilterChoiceBox

import javafx.util.StringConverter; //導入依賴的package包/類
private void initializeExpressionsSortFilterChoiceBox() {
    expressionSorterChoiceBox.setItems(FXCollections.observableArrayList(ExpressionSortOrder.values()));
    expressionSorterChoiceBox.getSelectionModel().select(expressionSortOrder);
    expressionSorterChoiceBox.setConverter(new StringConverter<ExpressionSortOrder>() {
        @Override
        public String toString(ExpressionSortOrder object) {
            return object.getDisplayName();
        }

        @Override
        public ExpressionSortOrder fromString(String string) {
            return null;
        }
    });
    expressionSorterChoiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ExpressionSortOrder>() {
        @Override
        public void changed(ObservableValue observable, ExpressionSortOrder oldValue, ExpressionSortOrder newValue) {
            expressionSortOrder = newValue;
            populateExpressionsListView();
        }
    });
}
 
開發者ID:CIRDLES,項目名稱:Squid,代碼行數:23,代碼來源:ExpressionManagerController.java

示例3: setUpNodeColorSchemeComboBox

import javafx.util.StringConverter; //導入依賴的package包/類
/**
 * Sets up the {@link ComboBox} listing all node color scheme choices.
 */
private void setUpNodeColorSchemeComboBox() {
    nodeColorScheme.setConverter(new StringConverter<Pair<String, ColorScheme>>() {
        @Override
        public String toString(final Pair<String, ColorScheme> object) {
            return object.getKey();
        }

        @Override
        public Pair<String, ColorScheme> fromString(final String string) {
            return NODE_COLOR_SCHEMES.stream()
                    .filter(pair -> pair.getKey().equals(string))
                    .collect(Collectors.toList()).get(0);
        }
    });
    nodeColorScheme.getItems().addAll(NODE_COLOR_SCHEMES);
    nodeColorScheme.getSelectionModel().selectFirst();
}
 
開發者ID:ProgrammingLife2017,項目名稱:hygene,代碼行數:21,代碼來源:BasicSettingsViewController.java

示例4: commitEditorText

import javafx.util.StringConverter; //導入依賴的package包/類
private void commitEditorText(Spinner<T> spinner) {
    if (!spinner.isEditable()) return;
    try {
        String text = spinner.getEditor().getText();
        SpinnerValueFactory<T> valueFactory = spinner.getValueFactory();
        if (valueFactory != null) {
            StringConverter<T> converter = valueFactory.getConverter();
            if (converter != null) {
                T value = converter.fromString(text);
                if (value == null)
                    return;
                valueFactory.setValue(value);
            }
        }
    } catch (NumberFormatException e) {
        // Ignore text input.
        return;
    }
}
 
開發者ID:tbressler,項目名稱:waterrower-workout,代碼行數:20,代碼來源:SpinnerFocusChangeListener.java

示例5: apiVersionLine

import javafx.util.StringConverter; //導入依賴的package包/類
private void apiVersionLine( final GridPane parent ) {
    final Label lineLabel = new Label( "Api Version:" );
    parent.add( lineLabel, 0, 2 );

    final ComboBox<ApiVersion> apiVersionBox = new ComboBox<>( FXCollections.observableArrayList( ApiVersion.values( ) ) );
    apiVersionBox.converterProperty( ).setValue( new StringConverter<ApiVersion>( ) {
        @Override
        public String toString( final ApiVersion object ) {
            return object.getName( );
        }

        @Override
        public ApiVersion fromString( final String string ) {
            return ApiVersion.fromName( string );
        }
    } );
    apiVersionBox.getSelectionModel( ).select( _model.getApiVersion( ) );
    apiVersionBox.getSelectionModel( ).selectedItemProperty( ).addListener( ( o, oldValue, newValue ) -> _model.requestNewApiVersion( newValue ) );
    lineLabel.setLabelFor( apiVersionBox );
    parent.add( apiVersionBox, 1, 2 );
}
 
開發者ID:u2032,項目名稱:wall-t,代碼行數:22,代碼來源:ConfigurationView.java

示例6: initialize

import javafx.util.StringConverter; //導入依賴的package包/類
@Override
public void initialize(URL location, ResourceBundle resources) {
	// TODO Auto-generated method stub
	choixSchema.getItems().add(main.getDefaultSchema());
	for (Projet p : main.getProjects()) {
		choixSchema.getItems().add(p.getSchemaProjet());
	}
	// change the text to make it pretty
	choixSchema.setConverter(new StringConverter<Schema>() {
		
		@Override
		public String toString(Schema object) {
			// TODO Auto-generated method stub
			return object.getName();
		}
		
		@Override
		public Schema fromString(String string) {
			// TODO Auto-generated method stub
			return new Schema(string);
		}
	});
}
 
開發者ID:coco35700,項目名稱:uPMT,代碼行數:24,代碼來源:NewProjectDialogController.java

示例7: createMarginFields

import javafx.util.StringConverter; //導入依賴的package包/類
private void createMarginFields() {
    NumericTextField topField = new NumericTextField();
    NumericTextField rightField = new NumericTextField();
    NumericTextField bottomField = new NumericTextField();
    NumericTextField leftField = new NumericTextField();

    StringConverter<Number> converter = new NumberStringConverter();

    leftField.textProperty().bindBidirectional(getSkinnable().leftMarginProperty(), converter);
    rightField.textProperty().bindBidirectional(getSkinnable().rightMarginProperty(), converter);
    topField.textProperty().bindBidirectional(getSkinnable().topMarginProperty(), converter);
    bottomField.textProperty().bindBidirectional(getSkinnable().bottomMarginProperty(), converter);

    marginsGridPane = new GridPane();
    marginsGridPane.getStyleClass().add("custom-fields");
    marginsGridPane.add(new Label(Messages.getString("MarginSelector.TOP")), 0, 0);
    marginsGridPane.add(topField, 1, 0);
    marginsGridPane.add(new Label(Messages.getString("MarginSelector.RIGHT")), 2, 0);
    marginsGridPane.add(rightField, 3, 0);
    marginsGridPane.add(new Label(Messages.getString("MarginSelector.BOTTOM")), 0, 1);
    marginsGridPane.add(bottomField, 1, 1);
    marginsGridPane.add(new Label(Messages.getString("MarginSelector.LEFT")), 2, 1);
    marginsGridPane.add(leftField, 3, 1);
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:25,代碼來源:PaperViewSkin.java

示例8: forConvictionConverter

import javafx.util.StringConverter; //導入依賴的package包/類
public static StringConverter<Conviction> forConvictionConverter(Translator translator) {
    return new StringConverter<Conviction>() {
        @Override
        public String toString(Conviction object) {
            if (object == null) {
                return "";
            }

            return translator.getConvictionList().get(object.ordinal());
        }

        @Override
        public Conviction fromString(String string) {
            return Conviction.valueOf(string);
        }
    };
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:18,代碼來源:StringConvertors.java

示例9: forRaceConverter

import javafx.util.StringConverter; //導入依賴的package包/類
public static StringConverter<Race> forRaceConverter(Translator translator) {
    return new StringConverter<Race>() {
        @Override
        public String toString(Race object) {
            if (object == null) {
                return "";
            }

            return translator.getRaceList().get(object.ordinal());
        }

        @Override
        public Race fromString(String string) {
            return Race.valueOf(string);
        }
    };
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:18,代碼來源:StringConvertors.java

示例10: forProfessionConverter

import javafx.util.StringConverter; //導入依賴的package包/類
public static StringConverter<Profession> forProfessionConverter(Translator translator) {
    return new StringConverter<Profession>() {
        @Override
        public String toString(Profession object) {
            if (object == null) {
                return "";
            }

            return translator.getProfessionList().get(object.ordinal());
        }

        @Override
        public Profession fromString(String string) {
            return Profession.valueOf(string);
        }
    };
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:18,代碼來源:StringConvertors.java

示例11: forAdditionType

import javafx.util.StringConverter; //導入依賴的package包/類
public static StringConverter<DiceHelper.AdditionType> forAdditionType(Translator translator) {
    return new StringConverter<AdditionType>() {
        @Override
        public String toString(AdditionType object) {
            if (object == null) {
                return "";
            }

            return translator.getDiceAdditionProertyList().get(object.ordinal());
        }

        @Override
        public AdditionType fromString(String string) {
            return AdditionType.valueOf(string);
        }
    };
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:18,代碼來源:StringConvertors.java

示例12: forMeleWeaponType

import javafx.util.StringConverter; //導入依賴的package包/類
public static StringConverter<MeleWeapon.MeleWeaponType> forMeleWeaponType(
    Translator translator) {
    return new StringConverter<MeleWeaponType>() {
        @Override
        public String toString(MeleWeaponType object) {
            if (object == null) {
                return "";
            }

            return translator.getWeaponMeleTypeList().get(object.ordinal());
        }

        @Override
        public MeleWeaponType fromString(String string) {
            return MeleWeaponType.valueOf(string);
        }
    };
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:19,代碼來源:StringConvertors.java

示例13: forMeleWeaponClass

import javafx.util.StringConverter; //導入依賴的package包/類
public static StringConverter<MeleWeapon.MeleWeaponClass> forMeleWeaponClass(
    Translator translator) {
    return new StringConverter<MeleWeaponClass>() {
        @Override
        public String toString(MeleWeaponClass object) {
            if (object == null) {
                return "";
            }

            return translator.getWeaponMeleClassList().get(object.ordinal());
        }

        @Override
        public MeleWeaponClass fromString(String string) {
            return MeleWeaponClass.valueOf(string);
        }
    };
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:19,代碼來源:StringConvertors.java

示例14: forRangedWeaponType

import javafx.util.StringConverter; //導入依賴的package包/類
public static StringConverter<RangedWeapon.RangedWeaponType> forRangedWeaponType(
    Translator translator) {
    return new StringConverter<RangedWeaponType>() {
        @Override
        public String toString(RangedWeaponType object) {
            if (object == null) {
                return "";
            }

            return translator.getWeaponRangedTypeList().get(object.ordinal());
        }

        @Override
        public RangedWeaponType fromString(String string) {
            return RangedWeaponType.valueOf(string);
        }
    };
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:19,代碼來源:StringConvertors.java

示例15: initializeLanguageChoiceBox

import javafx.util.StringConverter; //導入依賴的package包/類
/**
 * Initializes the language ChoiceBox, retrieving all the available languages
 */
protected void initializeLanguageChoiceBox() {
    ResourceBundle i18nMessages = this.scrabble.getI18nMessages();
    List<LanguageInterface> availableLanguages = Arrays.asList(new French(), new English());

    this.languageChoiceBox.getItems().addAll(availableLanguages);
    this.languageChoiceBox.setValue(availableLanguages.get(0));
    this.languageChoiceBox.setConverter(new StringConverter<LanguageInterface>() {
        @Override
        public String toString(LanguageInterface object) {
            return i18nMessages.getString(object.getName());
        }

        @Override
        public LanguageInterface fromString(String string) {
            return null;
        }
    });
}
 
開發者ID:Chrisp1tv,項目名稱:ScrabbleGame,代碼行數:22,代碼來源:NewGameController.java


注:本文中的javafx.util.StringConverter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。