本文整理汇总了Java中javafx.scene.input.KeyCode类的典型用法代码示例。如果您正苦于以下问题:Java KeyCode类的具体用法?Java KeyCode怎么用?Java KeyCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KeyCode类属于javafx.scene.input包,在下文中一共展示了KeyCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTextField
import javafx.scene.input.KeyCode; //导入依赖的package包/类
private void createTextField() {
textField = new TextField(getString());
textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> arg0,
Boolean arg1, Boolean arg2) {
if (!arg2) {
commitEdit(textField.getText());
}
}
});
textField.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent ke) {
KeyCode kc = ke.getCode();
if ((kc.equals(KeyCode.ENTER) || kc.equals(KeyCode.UP) || kc.equals(KeyCode.DOWN) || kc.equals(KeyCode.LEFT) || kc.equals(KeyCode.RIGHT))) {
commitEdit(textField.getText());
}
}
});
}
示例2: txtNomeSoftware_onKeyPressed
import javafx.scene.input.KeyCode; //导入依赖的package包/类
@FXML
void txtNomeSoftware_onKeyPressed(KeyEvent event) {
if (event.getCode() == KeyCode.ENTER) {
if (txtNomeSoftware.getText().equals("")) {
preencherTableViewRequisitos(software.buscarTodosSoftwares());
} else {
preencherTableViewRequisitos(software.buscarPorNome(txtNomeSoftware.getText()));
}
}
}
示例3: createTextField
import javafx.scene.input.KeyCode; //导入依赖的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;
}
示例4: thumbKeyPressed
import javafx.scene.input.KeyCode; //导入依赖的package包/类
@FXML
void thumbKeyPressed(KeyEvent e) {
if (e.getCode() == KeyCode.BACK_SPACE || e.getCode() == KeyCode.DELETE) {
gradientPicker.removeStop(this);
// Called when removing a gradient stop :
// - update gradient preview accordingly
// - update model
final PaintPickerController paintPicker
= gradientPicker.getPaintPickerController();
final Mode mode = paintPicker.getMode();
final Paint value = gradientPicker.getValue(mode);
gradientPicker.updatePreview(value);
// Update model
paintPicker.setPaintProperty(value);
e.consume();
}
}
示例5: onKeyPressed
import javafx.scene.input.KeyCode; //导入依赖的package包/类
private void onKeyPressed(KeyEvent event) {
if (event.getCode() == KeyCode.ESCAPE) {
handleSelection(Selection.CANCEL);
} else if (event.getCode() == KeyCode.ENTER) {
Node focusOwner = root.getScene().getFocusOwner();
if (focusOwner instanceof Button) {
((Button) (focusOwner)).fire();
}
}
}
示例6: openSubmitAction
import javafx.scene.input.KeyCode; //导入依赖的package包/类
@FXML
public void openSubmitAction(ActionEvent event) throws IOException {
Node node = (Node) event.getSource();
final Stage stage = (Stage) node.getScene().getWindow();
final Parent home = FXMLLoader.load(getClass().getResource("/fxml/Homepage.fxml"));
final Scene hScene = new Scene(home);
Parent root = FXMLLoader.load(getClass().getResource("/fxml/Submit.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
root.setOnKeyPressed(new EventHandler<KeyEvent>() {
public void handle(KeyEvent ke) {
if (ke.getCode() == KeyCode.ESCAPE) {
System.out.println("Key Pressed: " + ke.getCode());
stage.setScene(hScene);
}
}
});
}
示例7: updateVector
import javafx.scene.input.KeyCode; //导入依赖的package包/类
/**
* Update the vector.
*
* @param event the event
*/
@FXThread
protected void updateVector(@Nullable final KeyEvent event) {
if (isIgnoreListener() || (event != null && event.getCode() != KeyCode.ENTER)) return;
final FloatTextField xField = getXField();
final float x = xField.getValue();
final FloatTextField yFiled = getYFiled();
final float y = yFiled.getValue();
final FloatTextField zField = getZField();
final float z = zField.getValue();
final Vector3f oldValue = getPropertyValue() == null ? Vector3f.ZERO : getPropertyValue();
final Vector3f newValue = new Vector3f();
newValue.set(x, y, z);
changed(newValue, oldValue.clone());
}
示例8: EpiStats
import javafx.scene.input.KeyCode; //导入依赖的package包/类
public EpiStats(Arguments args) {
super(args, "EpiStats", "1.6.0");
initServices(Executors.newSingleThreadExecutor());
Platform.runLater(() -> {
initStage(1000, 800, true, ResourceUtil.loadImage("favicon.png"));
Path dir = getWorkingDirectory();
setScene(new UserInterface(this, dir.resolve("ui.dat"), new ObjectList(dir.resolve("objects.olist")), new PlayerCache(dir.resolve("cache/")))).show();
Scene sc = getStage().getScene();
sc.setOnKeyPressed((e) -> {
if (e.getCode() == KeyCode.ENTER) {
Node n = sc.getFocusOwner();
if (n instanceof Button)
((Button) n).fire();
}
});
});
checkForUpdate();
}
示例9: batchKeyReleaseEvent
import javafx.scene.input.KeyCode; //导入依赖的package包/类
public void batchKeyReleaseEvent() {
batch.getEditor().setOnKeyReleased((KeyEvent keyEvent) -> {
if (keyEvent.getCode().isLetterKey() || keyEvent.getCode().isDigitKey() || keyEvent.getCode() == KeyCode.BACK_SPACE) {
String Batch = batch.getEditor().getText();
ObservableList<String> sorted_batch_list = FXCollections.observableArrayList();
batch.setItems(sorted_batch_list);
Iterator it = batch_list.iterator();
while (it.hasNext()) {
String batch_item = it.next().toString();
if (batch_item.contains(Batch)) {
sorted_batch_list.add(batch_item);
}
}
if (Batch.equals("")) {
batch.hide();
batch.setItems(batch_list);
} else if (sorted_batch_list.size() == 0) {
batch.hide();
} else
batch.show();
}
});
}
示例10: updateRotation
import javafx.scene.input.KeyCode; //导入依赖的package包/类
/**
* Updating rotation.
*/
@FXThread
private void updateRotation(@Nullable final KeyEvent event) {
if (isIgnoreListener() || (event != null && event.getCode() != KeyCode.ENTER)) return;
final Quaternion oldValue = notNull(getPropertyValue());
final FloatTextField xField = getXField();
final float x = degreeToRadians(xField.getValue());
final FloatTextField yFiled = getYFiled();
final float y = degreeToRadians(yFiled.getValue());
final FloatTextField zField = getZField();
final float z = degreeToRadians(zField.getValue());
final Quaternion newValue = new Quaternion();
newValue.fromAngles(ArrayFactory.toFloatArray(x, y, z));
changed(newValue, oldValue.clone());
}
示例11: getModifierEx
import javafx.scene.input.KeyCode; //导入依赖的package包/类
@SuppressWarnings("deprecation") public int getModifierEx() {
int modifiersEx = 0;
if (shiftPressed) {
modifiersEx |= KeyCode.SHIFT.impl_getCode();
}
if (ctrlPressed) {
modifiersEx |= KeyCode.CONTROL.impl_getCode();
}
if (altPressed) {
modifiersEx |= KeyCode.ALT.impl_getCode();
}
if (metaPressed) {
modifiersEx |= KeyCode.META.impl_getCode();
}
return modifiersEx;
}
示例12: testPressAndReleaseKeys_withAlt
import javafx.scene.input.KeyCode; //导入依赖的package包/类
public void testPressAndReleaseKeys_withAlt() {
kss.clear();
driver.pressKey(textField, JavaAgentKeys.ALT);
driver.pressKey(textField, JavaAgentKeys.F1);
driver.releaseKey(textField, JavaAgentKeys.F1);
driver.releaseKey(textField, JavaAgentKeys.ALT);
List<String> list = Arrays.asList("Alt pressed " + KeyCode.getKeyCode("Alt"), "Alt pressed " + KeyCode.getKeyCode("F1"),
"Alt released " + KeyCode.getKeyCode("F1"), "released " + KeyCode.getKeyCode("Alt"));
final String expected = list.toString();
new WaitWithoutException() {
@Override public boolean until() {
return expected.equals(kss.toString());
}
}.wait("List is empty", 3000, 500);
AssertJUnit.assertEquals(expected, kss.toString());
}
示例13: VisionControl
import javafx.scene.input.KeyCode; //导入依赖的package包/类
public VisionControl() {
slider = new Slider();
slider.setMin(0.0);
slider.setMax(255.0);
slider.setValue(0.0);
slider.setMaxWidth(350.0);
slider.setDisable(true);
inputText = new TextField();
inputText.setText("0");
inputText.setMaxWidth(50.0);
inputText.setOnKeyPressed((e)->{
if(e.getCode() == KeyCode.ENTER){
setTextFromField();
}
});
inputText.focusedProperty().addListener((obs, o, n)->{
if(!n.booleanValue()){
inputText.setText(String.valueOf((int)slider.getValue()));
}
});
slider.valueProperty().addListener((obs, o, n)->{
inputText.setText(String.valueOf((int)slider.getValue()));
});
nameLabel = new Label("");
HBox top = new HBox();
top.setSpacing(5.0);
top.getChildren().addAll(nameLabel, inputText);
VBox all = new VBox();
all.setSpacing(10.0);
all.getChildren().addAll(top, slider);
root = all;
}
示例14: openStatisticsAction
import javafx.scene.input.KeyCode; //导入依赖的package包/类
@FXML
public void openStatisticsAction(ActionEvent event) throws IOException {
Node node = (Node) event.getSource();
final Stage stage = (Stage) node.getScene().getWindow();
Parent root = FXMLLoader.load(getClass().getResource("/fxml/Statistics.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
final Parent home = FXMLLoader.load(getClass().getResource("/fxml/Homepage.fxml"));
final Scene hScene = new Scene(home);
root.setOnKeyPressed(new EventHandler<KeyEvent>() {
public void handle(KeyEvent ke) {
if (ke.getCode() == KeyCode.ESCAPE) {
System.out.println("Key Pressed: " + ke.getCode());
stage.setScene(hScene);
}
}
});
}
示例15: Thumb2CodeArea
import javafx.scene.input.KeyCode; //导入依赖的package包/类
public Thumb2CodeArea() {
getStylesheets().clear();
getStylesheets().add(Thumb2CodeArea.class.getClassLoader()
.getResource("styles/thumb2-syntax-highlight.css").toExternalForm());
getStylesheets().add(Thumb2CodeArea.class.getClassLoader()
.getResource("styles/spellchecking.css").toExternalForm());
setCursor(Cursor.TEXT);
richChanges().filter(ch -> !ch.getInserted().equals(ch.getRemoved()))
.subscribe(change -> {
SyntaxHighlighter syntaxHighlighter = new SyntaxHighlighter();
setStyleSpans(0, syntaxHighlighter.highlight(getText()));
});
addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent e) -> {
if(e.getCode() == KeyCode.TAB) {
String s = " ";
insertText(getCaretPosition(), s);
e.consume();
}
});
}