本文整理汇总了Java中javafx.scene.control.TextFormatter类的典型用法代码示例。如果您正苦于以下问题:Java TextFormatter类的具体用法?Java TextFormatter怎么用?Java TextFormatter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextFormatter类属于javafx.scene.control包,在下文中一共展示了TextFormatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
@Override
public void initialize(final URL location, final ResourceBundle resources) {
final ObjectProperty<GfaNode> selectedNodeProperty = graphVisualizer.getSelectedSegmentProperty();
selectedNodeProperty.addListener((observable, oldValue, newValue) ->
nodePosition.setText(newValue == null ? "" : String.valueOf(newValue.getSegmentIds())));
radius.textProperty().bind(graphDimensionsCalculator.getRadiusProperty().asString());
baseOffset.setTextFormatter(new TextFormatter<>(new IntegerStringConverter()));
baseOffset.setText(String.valueOf(sequenceVisualizer.getOffsetProperty().get()));
baseOffset.textProperty().addListener((observable, oldValue, newValue) -> updateBaseOffset(newValue));
sequenceVisualizer.getOffsetProperty().addListener((observable, oldValue, newValue) ->
baseOffset.setText(String.valueOf(newValue)));
saveButton.disableProperty().bind(selectedNodeProperty.isNull());
}
示例2: initialize
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
@Override
public void initialize(final URL location, final ResourceBundle resources) {
sequenceVisualizer.setCanvas(sequenceCanvas);
setOffset.setTextFormatter(new TextFormatter<>(new IntegerStringConverter()));
sequenceVisualizer.getOffsetProperty().addListener((observable, oldValue, newValue) -> {
setOffset.setText(String.valueOf(newValue));
sequenceTextArea.positionCaret(newValue.intValue());
sequenceTextArea.selectPositionCaret(newValue.intValue() + 1);
});
graphVisualizer.getSelectedSegmentProperty()
.addListener((observable, oldNode, newNode) -> updateFields(newNode));
sequenceCanvas.widthProperty().bind(sequenceGrid.widthProperty().subtract(CANVAS_PADDING * 2));
sequenceViewPane.visibleProperty().bind(sequenceVisualizer.getVisibleProperty()
.and(graphStore.getGfaFileProperty().isNotNull()));
sequenceViewPane.managedProperty().bind(sequenceVisualizer.getVisibleProperty()
.and(graphStore.getGfaFileProperty().isNotNull()));
}
示例3: addNumericValidation
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
private static void addNumericValidation(TextField field) {
field.getProperties().put("vkType", "numeric");
field.setTextFormatter(new TextFormatter<>(c -> {
if (c.isContentChange()) {
if (c.getControlNewText().length() == 0) {
return c;
}
try {
Integer.parseInt(c.getControlNewText());
return c;
} catch (NumberFormatException e) {
}
return null;
}
return c;
}));
}
示例4: AbstractNumberField
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
protected AbstractNumberField() {
super();
setText("0");
setNumber(getNumberFromText("0"));
setTextFormatter(new TextFormatter<>(change -> {
String text = change.getControlNewText();
if (isStartOfNumber(text)) {
return change;
}
return null;
}));
PropertyUtils.bindBidirectionalWithConverter(
textProperty(),
number,
text -> isCompleteNumber(text) ? getNumberFromText(text) : getNumber(),
num -> Objects.equals(num, getNumberFromText(getText())) ? getText() : num.toString());
}
示例5: initialize
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
@FXML
void initialize() {
UnaryOperator<TextFormatter.Change> filter = change -> {
String text = change.getText();
if (text.matches("[0-9]*")) {
return change;
}
return null;
};
TextFormatter<String> textFormatter1 = new TextFormatter<>(filter);
TextFormatter<String> textFormatter2 = new TextFormatter<>(filter);
controlPortTextField.setTextFormatter(textFormatter1);
framegrabPortTextField.setTextFormatter(textFormatter2);
load();
}
开发者ID:mbari-media-management,项目名称:vars-annotation,代码行数:19,代码来源:SharktopodaSettingsPaneController.java
示例6: initialize
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
@FXML
void initialize() {
UnaryOperator<TextFormatter.Change> filter = change -> {
String text = change.getText();
if (text.matches("[0-9]*")) {
return change;
}
return null;
};
TextFormatter<String> textFormatter1 = new TextFormatter<>(filter);
sequenceNumberTextField.setTextFormatter(textFormatter1);
cameraIdComboBox.setEditable(true);
}
示例7: DecimalTextField
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
public DecimalTextField(@NamedArg("formatPattern") String formatPattern, @NamedArg("locale") Locale locale) {
format = new DecimalFormat(formatPattern, new DecimalFormatSymbols(locale));
DecimalFilter filter = new DecimalFilter(format);
super.setTextFormatter(new TextFormatter<>(filter));
new DecimalFilter().getFormat().getDecimalFormatSymbols().getDecimalSeparator();
textProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.endsWith(String.valueOf(filter.getFormat().getDecimalFormatSymbols().getDecimalSeparator()))) {
newValue = newValue.substring(0, newValue.length() - 1);
}
if (newValue.isEmpty()) {
newValue = "0";
}
try {
value.setValue(format.parse(newValue));
} catch (ParseException e) {
value.setValue(0);
}
});
}
示例8: setTextFormatter
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
public void setTextFormatter(TextFormatter<?> value) {
if (value == null) {
throw new IllegalArgumentException("TextFormatter value cannot be null.");
}
filter = value.getFilter();
innerTextField.setTextFormatter(new TextFormatter<>(change -> {
if (useAutoTitles && titleLabel.getText().isEmpty()) {
if (change.getText().equals(delimiter)) {
for (Map.Entry<String, String> entry : autoTitles.entrySet()) {
if (change.getControlNewText().startsWith(entry.getKey())) {
TitledTextFieldBox.this.setTitle(entry.getValue());
innerTextField.setText("");
return null;
}
}
}
}
return filter.apply(change);
}));
}
示例9: apply
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
@Override
public TextFormatter.Change apply(TextFormatter.Change change) {
if (change.getControlNewText().isEmpty()) {
return change;
}
String text = change.getControlNewText();
String[] split = text.split(" ");
if (split.length == 2 && change.getText().equals(" ")) {
return null;
}
if (Arrays.stream(split).allMatch(s -> {
if (s.startsWith("+")) {
s = s.substring(1);
if (s.isEmpty()) return true;
}
ParsePosition parsePosition = new ParsePosition(0);
Object object = format.parse(s, parsePosition);
return (!(object == null || parsePosition.getIndex() < s.length()));
})) {
return change;
}
return null;
}
示例10: changeAmount
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
private void changeAmount(Object source, Flow flow, ViewContext context, TableKey key) {
final long id = key.get("id");
TextFormatter<BigDecimal> amount = new TextFormatter<>(new BigDecimalConverter());
TextFormatter<BigDecimal> amountReserved = new TextFormatter<>(new BigDecimalConverter());
TextField comment = new TextField();
boolean ok = MDialogs.create(context.getRootNode(), "Transfer Stock Unit")
.input("Amount", Filters.of(amount,8))
.input("Reserved", Filters.of(amountReserved,8))
.input("Comment", comment)
.showOkCancel();
if (!ok) return;
BigDecimal amountVal = amount.getValue();
BigDecimal resVal = amountReserved.getValue();
String commentVal = comment.getText();
StockUnitCRUDRemote suCrud = context.getBean(StockUnitCRUDRemote.class);
ManageInventoryFacade manageInventory = context.getBean(ManageInventoryFacade.class);
context.getExecutor().call(() -> {
StockUnit su = suCrud.retrieve(id);
manageInventory.changeAmount(new StockUnitTO(su), amountVal, resVal, commentVal);
return null;
});
}
示例11: NumberTextField
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
public NumberTextField(NumberFormat format, double min, double max) {
super();
this.min = min;
this.max = max;
this.setTextFormatter(new TextFormatter<>((c) -> {
if(c.getControlNewText().isEmpty()) return c;
ParsePosition parsePosition = new ParsePosition(0);
Number num = format.parse(c.getControlNewText(), parsePosition);
if(num == null || parsePosition.getIndex() < c.getControlNewText().length() || num.doubleValue() < this.min || num.doubleValue() > this.max) return null;
return c;
}));
}
示例12: showNewTabColumnsDialog
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
/**
* Third entry. This if it returns a value actually creates the tab
*/
void showNewTabColumnsDialog(String name, int rows) {
logger.info("showNewTabColumnsDialog was called with the data: " + name + " & " + rows);
if (rows > 0) {
finishNewTabDialogs(rows, 0, name);
return;
}
TextInputDialog inputDialog = new TextInputDialog();
inputDialog.setContentText("Enter the number of columns to apply to the tab");
inputDialog.getEditor().setTextFormatter(new TextFormatter<Integer>(new IntegerStringConverter()));
inputDialog.getEditor().setText("0");
inputDialog.setHeaderText(null);
inputDialog.setTitle("New Tab Columns");
inputDialog.showAndWait()
.filter(response -> !"".equals(response))
.ifPresent( response -> this.finishNewTabDialogs(rows, Integer.parseInt(response), name));
}
示例13: initialize
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
@Override
public void initialize(final URL location, final ResourceBundle resources) {
nodeId.setTextFormatter(new TextFormatter<>(new NumberStringConverter()));
radius.setTextFormatter(new TextFormatter<>(new NumberStringConverter()));
currentNodeId.textProperty().bind(graphDimensionsCalculator.getCenterNodeIdProperty().asString());
currentRadius.textProperty().bind(graphDimensionsCalculator.getRadiusProperty().asString());
graphDimensionsCalculator.getCenterNodeIdProperty().addListener(
(observable, oldValue, newValue) -> nodeId.setText(String.valueOf(newValue)));
graphDimensionsCalculator.getRadiusProperty().addListener(
(observable, oldValue, newValue) -> radius.setText(String.valueOf(newValue)));
}
示例14: initialize
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
@FXML
public void initialize(URL url, ResourceBundle rb) {
UnaryOperator<TextFormatter.Change> filter = c -> {
String proposedText = c.getControlNewText();
if (proposedText.matches(".{0,15}")) {
return c ;
} else {
return null ;
}
};
namePlayer1.setTextFormatter(new TextFormatter<String>(filter));
namePlayer2.setTextFormatter(new TextFormatter<String>(filter));
}
示例15: initialize
import javafx.scene.control.TextFormatter; //导入依赖的package包/类
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
UnaryOperator<TextFormatter.Change> filter = c -> {
String proposedText = c.getControlNewText();
if (proposedText.matches(".{0,15}")) {
return c ;
} else {
return null ;
}
};
playerName.setTextFormatter(new TextFormatter<String>(filter));
}