本文整理匯總了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();
}
});
}