本文整理汇总了Java中javafx.scene.control.TextField.addEventFilter方法的典型用法代码示例。如果您正苦于以下问题:Java TextField.addEventFilter方法的具体用法?Java TextField.addEventFilter怎么用?Java TextField.addEventFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.control.TextField
的用法示例。
在下文中一共展示了TextField.addEventFilter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createField
import javafx.scene.control.TextField; //导入方法依赖的package包/类
private void createField() {
field = new TextField(getString());
field.setEditable(false);
field.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
if (e.getCode() == KeyCode.ENTER) {
try {
commitEdit(KeyCombination.valueOf(field.getText()));
} catch (Exception ee) {
cancelEdit();
}
} else if (e.getCode() == KeyCode.ESCAPE) {
cancelEdit();
} else {
field.setText(convert(e).toString());
}
e.consume();
});
}
示例2: giveSearchBarHotkey
import javafx.scene.control.TextField; //导入方法依赖的package包/类
public static void giveSearchBarHotkey(TextField scene){
scene.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
public void handle(final KeyEvent keyEvent) {
if (KeyCode.ENTER == keyEvent.getCode()) {
try {
App.getMainController().open(App.getMainController().getSearchList().getList().getItems().get(0));
keyEvent.consume();
} catch (Exception e) {
}
}
}
});
}
示例3: setTextFieldNumbersOnly
import javafx.scene.control.TextField; //导入方法依赖的package包/类
public static void setTextFieldNumbersOnly(TextField field, int min, int max) {
field.addEventFilter(KeyEvent.KEY_TYPED, (e) -> {
if (e.getCharacter().matches("[0-9]")) {
String text = field.getText();
if (e.getCode() == KeyCode.BACK_SPACE && text.length() > 0) {
text = text.substring(0, text.length() - 2);
} else {
text = text + e.getCharacter();
}
try {
long value = Long.parseLong(text);
if (value < min) {
e.consume();
field.setText(String.valueOf(min));
} else if (value > max) {
e.consume();
field.setText(String.valueOf(max));
}
} catch (NumberFormatException ex) {
e.consume();
}
} else {
e.consume();
}
});
}
示例4: lauch
import javafx.scene.control.TextField; //导入方法依赖的package包/类
void lauch(Board b) {
board = b;
p1Label.setText("Joueur " + board.getPlayers().get(0).getColor());
p2Label.setText("Joueur " + board.getPlayers().get(1).getColor());
p3Label.setText("Joueur " + board.getPlayers().get(2).getColor());
setPlayerInitialPosition(board.getPlayers().get(0), p1TextField);
setPlayerInitialPosition(board.getPlayers().get(1), p2TextField);
setPlayerInitialPosition(board.getPlayers().get(2), p3TextField);
if (board.getPlayers().size() == 4) {
p4Label.setText("Joueur " + board.getPlayers().get(3).getColor());
setPlayerInitialPosition(board.getPlayers().get(3), p4TextField);
} else {
p4Label.setVisible(false);
p4TextField.setVisible(false);
}
tf.add(p1TextField);
tf.add(p2TextField);
tf.add(p3TextField);
tf.add(p4TextField);
for (TextField textField : tf) {
textField.addEventFilter(KeyEvent.KEY_TYPED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent inputevent) {
if (!inputevent.getCharacter().matches("\\d")) {
inputevent.consume();
}
}
});
}
}
示例5: executeOnFocusLostOrEnter
import javafx.scene.control.TextField; //导入方法依赖的package包/类
public static void executeOnFocusLostOrEnter(TextField textField, Runnable runnable) {
textField.focusedProperty().addListener((v, o, n) -> {
if (!n) {
runnable.run();
}
});
textField.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode().equals(KeyCode.ENTER)) {
runnable.run();
}
});
}