本文整理汇总了Java中javafx.scene.control.TextField.setOnAction方法的典型用法代码示例。如果您正苦于以下问题:Java TextField.setOnAction方法的具体用法?Java TextField.setOnAction怎么用?Java TextField.setOnAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.control.TextField
的用法示例。
在下文中一共展示了TextField.setOnAction方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTextField
import javafx.scene.control.TextField; //导入方法依赖的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;
}
示例2: WebViewPane
import javafx.scene.control.TextField; //导入方法依赖的package包/类
public WebViewPane() {
VBox.setVgrow(this, Priority.ALWAYS);
setMaxWidth(Double.MAX_VALUE);
setMaxHeight(Double.MAX_VALUE);
WebView view = new WebView();
view.setMinSize(500, 400);
view.setPrefSize(500, 400);
final WebEngine eng = view.getEngine();
eng.load("http://www.oracle.com/us/index.html");
final TextField locationField = new TextField("http://www.oracle.com/us/index.html");
locationField.setMaxHeight(Double.MAX_VALUE);
Button goButton = new Button("Go");
goButton.setDefaultButton(true);
EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
eng.load(locationField.getText().startsWith("http://") ? locationField.getText() :
"http://" + locationField.getText());
}
};
goButton.setOnAction(goAction);
locationField.setOnAction(goAction);
eng.locationProperty().addListener(new ChangeListener<String>() {
@Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
locationField.setText(newValue);
}
});
GridPane grid = new GridPane();
grid.setVgap(5);
grid.setHgap(5);
GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES);
GridPane.setConstraints(goButton,1,0);
GridPane.setConstraints(view, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS);
grid.getColumnConstraints().addAll(
new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true),
new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true)
);
grid.getChildren().addAll(locationField, goButton, view);
getChildren().add(grid);
}
示例3: WebViewSample
import javafx.scene.control.TextField; //导入方法依赖的package包/类
public WebViewSample() {
WebView webView = new WebView();
final WebEngine webEngine = webView.getEngine();
webEngine.load(DEFAULT_URL);
final TextField locationField = new TextField(DEFAULT_URL);
webEngine.locationProperty().addListener(new ChangeListener<String>() {
@Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
locationField.setText(newValue);
}
});
EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
webEngine.load(locationField.getText().startsWith("http://")
? locationField.getText()
: "http://" + locationField.getText());
}
};
locationField.setOnAction(goAction);
Button goButton = new Button("Go");
goButton.setDefaultButton(true);
goButton.setOnAction(goAction);
// Layout logic
HBox hBox = new HBox(5);
hBox.getChildren().setAll(locationField, goButton);
HBox.setHgrow(locationField, Priority.ALWAYS);
VBox vBox = new VBox(5);
vBox.getChildren().setAll(hBox, webView);
VBox.setVgrow(webView, Priority.ALWAYS);
getChildren().add(vBox);
}
示例4: EditableLabel
import javafx.scene.control.TextField; //导入方法依赖的package包/类
/**
* A text label that you can double click to edit.
*/
public EditableLabel() {
setMaxWidth(USE_PREF_SIZE);
Label label = new Label();
label.textProperty().bind(text);
label.visibleProperty().bind(Bindings.not(editing));
getChildren().add(label);
TextField editField = new AutoSizedTextField();
editField.visibleProperty().bind(editing);
editField.textProperty().bindBidirectional(text);
getChildren().add(editField);
setOnMouseClicked(mouseEvent -> {
if (mouseEvent.getClickCount() == 2) {
editing.set(true);
}
});
editField.setOnAction(__ae -> editing.set(false));
editField.focusedProperty().addListener((__, wasFocused, isFocused) -> {
if (!isFocused) {
editing.set(false);
}
});
editing.addListener((__, wasEditing, isEditing) -> {
if (isEditing) {
editField.requestFocus();
}
});
}
示例5: initGridPane
import javafx.scene.control.TextField; //导入方法依赖的package包/类
private GridPane initGridPane() {
GridPane gridPane = new GridPane();
//
TextField faddress = new TextField();
faddress.setPromptText("Enter server adders");
faddress.setOnAction(s -> client.makeConnection(faddress.getText()));
//text field init
TextField textField = new TextField();
textField.setPromptText("Enter command");
textField.setOnAction(s -> {
process(textField.getText());
textField.setText("");
});
//btn
Button button = new Button("Connect");
button.setOnAction(s -> client.makeConnection(faddress.getText()));
gridPane.add(button, 0, 0);
gridPane.add(faddress, 1, 0, 1, 1);
gridPane.add(clientConsole.view, 0, 1, 2, 1);
gridPane.add(textField, 0, 2, 2, 1);
gridPane.setAlignment(Pos.CENTER);
//grid settings
gridPane.setHgap(10);
gridPane.setVgap(10);
return gridPane;
}
示例6: getKeyspaceField
import javafx.scene.control.TextField; //导入方法依赖的package包/类
private TextField getKeyspaceField(int width) {
TextField keyspace = new TextField();
keyspace.setPromptText(localeService.getMessage("ui.menu.file.connect.keyspace.text"));
keyspace.setAlignment(Pos.TOP_CENTER);
keyspace.setMinWidth(width - 10);
keyspace.setMaxWidth(width - 10);
keyspace.setOnAction(this::handleClick);
return keyspace;
}
示例7: Controls
import javafx.scene.control.TextField; //导入方法依赖的package包/类
public Controls(ServerTab tab) {
super();
this.tab = tab;
ToolBar toolbar = new ToolBar();
Button disconnect = new Button("", AssetsLoader.getAssetView("disconnect.png", DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE));
Button broadcast = new Button("", AssetsLoader.getAssetView("broadcast.png", DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE));
Button enableKits = new Button("Allow all kits");
Button disableKits = new Button("Disallow all kits");
Button setNextMap = new Button("", AssetsLoader.getAssetView("next_map.png", DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE));
Button changeMap = new Button("", AssetsLoader.getAssetView("change_map.png", DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE));
Button setSlomo = new Button("Set slomo");
Button resetSlomo = new Button("Reset slomo");
Button enableVClaim = new Button("Enable vehicule claiming");
Button disableVClaim = new Button("Disable vehicule claiming");
disconnect.setTooltip(new Tooltip("Disconnect from server."));
broadcast.setTooltip(new Tooltip("Broadcast a message."));
changeMap.setTooltip(new Tooltip("Change current map. Be careful, this command will immediatly switch to the desired map."));
setNextMap.setTooltip(new Tooltip("Change the next played map."));
disconnect.setOnAction(this::disconnectAction);
enableKits.setOnAction(this::enableKitsAction);
disableKits.setOnAction(this::disableKitsAction);
setNextMap.setOnAction(this::setNextMapAction);
setSlomo.setOnAction(this::setSlomoAction);
resetSlomo.setOnAction(this::resetSlomoAction);
broadcast.setOnAction(this::broadcastAction);
enableVClaim.setOnAction(this::enableVClaimAction);
disableVClaim.setOnAction(this::disableVClaimAction);
changeMap.setOnAction(this::changeMapAction);
toolbar.getItems().add(disconnect);
toolbar.getItems().add(getSeparator());
toolbar.getItems().add(broadcast);
toolbar.getItems().add(getSeparator());
toolbar.getItems().addAll(setNextMap, changeMap);
// XXX not working atm, owi disabled them.
// toolbar.getItems().add(getSeparator());
// toolbar.getItems().addAll(enableKits, disableKits);
// toolbar.getItems().add(getSeparator());
// toolbar.getItems().addAll(setSlomo, resetSlomo);
// toolbar.getItems().add(getSeparator());
// toolbar.getItems().addAll(enableVClaim, disableVClaim);
consoleLogs = new TextArea();
consoleLogs.setEditable(false);
consoleLogs.textProperty().addListener((obs, oldV, newV) -> {
consoleLogs.setScrollTop(Double.MAX_VALUE);
});
manualCommandField = new TextField();
Button manualCommandButton = new Button("Send");
HBox manualPane = new HBox();
manualPane.getChildren().addAll(manualCommandField, manualCommandButton);
manualCommandField.prefWidthProperty().bind(consoleLogs.widthProperty());
manualCommandButton.setMaxWidth(70);
manualCommandButton.setMinWidth(70);
manualCommandButton.setOnAction(this::sendManualCommandAction);
manualCommandField.setOnAction(this::sendManualCommandAction);
this.setTop(toolbar);
this.setCenter(consoleLogs);
this.setBottom(manualPane);
}
示例8: AddMemberDialog
import javafx.scene.control.TextField; //导入方法依赖的package包/类
public AddMemberDialog(Organization organization) {
super();
this.organization = organization;
this.setTitle("Add a member");
this.setHeaderText("Search user");
ButtonType addButtonType = new ButtonType("Add selected", ButtonData.OK_DONE);
this.getDialogPane().getButtonTypes().addAll(addButtonType, ButtonType.CANCEL);
BorderPane mainPane = new BorderPane();
GridPane queryPane = new GridPane();
queryField = new TextField();
Button searchButton = new Button("Search");
searchButton.setOnAction(this::searchAction);
queryField.setOnAction(this::searchAction);
searchList = FXCollections.observableArrayList();
TableView<MemberView> searchResult = new TableView<>(searchList);
searchResult.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
TableColumn<MemberView, String> nameCol = new TableColumn<>("Name");
nameCol.setCellValueFactory(new PropertyValueFactory<>("username"));
searchResult.getColumns().add(nameCol);
queryPane.addRow(0, queryField, searchButton);
queryPane.setHgap(5);
resultCount = new Label();
queryPane.setPadding(new Insets(0, 0, 10, 0));
resultCount.setPadding(new Insets(10, 0, 0, 0));
mainPane.setTop(queryPane);
mainPane.setCenter(searchResult);
mainPane.setBottom(resultCount);
this.getDialogPane().setContent(mainPane);
this.setResultConverter(dialogButton -> {
if (dialogButton == addButtonType) {
Member result = searchResult.selectionModelProperty().get().getSelectedItem().getMember();
Alert conf = new Alert(AlertType.CONFIRMATION, "Do you really want to add " + result.getUsername() + " to your organization ?");
Optional<ButtonType> answer = conf.showAndWait();
if (answer.isPresent() && answer.get() == ButtonType.OK)
return result;
else
return null;
}
return null;
});
}
示例9: mkRoot
import javafx.scene.control.TextField; //导入方法依赖的package包/类
@Override
public Node mkRoot() {
GesturePane pane = new GesturePane();
WebView webview = new WebView();
WebEngine engine = webview.getEngine();
pane.addEventHandler(AffineEvent.CHANGED, e -> {
String script = String.format(
"document.getElementsByTagName('body')[0].style.transform = " +
"'matrix(%s,0,0,%s,%s,%s)';",
e.namedCurrent().scaleX(),
e.namedCurrent().scaleY(),
e.namedCurrent().translateX(),
e.namedCurrent().translateY());
engine.executeScript(script);
});
TextField bar = new TextField(INTERESTING_CSS);
bar.setOnAction(e -> engine.load(bar.getText()));
engine.load(bar.getText());
engine.documentProperty().addListener((o, p, n) -> {
if (n == null) return;
pane.zoomTo(1, Point2D.ZERO);
pane.setTarget(new Transformable() {
@Override
public double width() {
return Double.valueOf(engine.executeScript("document.body.scrollWidth")
.toString());
}
@Override
public double height() {
return Double.valueOf(engine.executeScript("document.body.scrollHeight")
.toString());
}
});
});
Label description = new Label("GesturePane supports Transformable implementation. This " +
"sample shows a WebView behind an empty GesturePane " +
"listening for AffineEvents. The Affine matrix is " +
"translated to CSS matrix and applied the the body " +
"element. \nBe aware that all mouse events will be " +
"consumed by the pane so you cannot click any " +
"links.");
description.setWrapText(true);
description.setPadding(new Insets(16));
StackPane glass = new StackPane(webview, pane);
glass.setPrefSize(0, 0);
VBox.setVgrow(glass, Priority.ALWAYS);
return new VBox(description, bar, glass);
}
示例10: openEditor
import javafx.scene.control.TextField; //导入方法依赖的package包/类
private void openEditor() {
final PopOver popOver = new PopOver();
final TextField textEditor = new TextField(targetText.getText());
BorderPane editorPane = new BorderPane(textEditor);
BorderPane.setMargin(textEditor, new Insets(12));
textEditor.setOnKeyReleased(e -> {
if ( KeyCode.ESCAPE.equals(e.getCode()) ) {
popOver.hide();
}
});
textEditor.setOnAction(e -> {
try {
setTargetValue(Double.parseDouble(textEditor.getText()));
fireTargeValueSet();
} catch ( NumberFormatException nfex ) {
Toolkit.getDefaultToolkit().beep();
} finally {
popOver.hide();
}
});
popOver.setContentNode(editorPane);
popOver.setDetachable(false);
popOver.setDetached(false);
popOver.setArrowLocation(PopOver.ArrowLocation.TOP_CENTER);
popOver.setHeaderAlwaysVisible(true);
popOver.setHideOnEscape(true);
popOver.setTitle("Set Target Value");
popOver.setAnimated(true);
popOver.setAutoHide(true);
popOver.setCloseButtonEnabled(true);
text.getScene().getStylesheets().stream().forEach(s -> popOver.getRoot().getStylesheets().add(s));
Bounds bounds = getBoundsInLocal();
Bounds screenBounds = localToScreen(bounds);
int x = (int) screenBounds.getMinX();
int y = (int) screenBounds.getMinY();
int w = (int) screenBounds.getWidth();
int h = (int) screenBounds.getHeight();
popOver.show(this, x + w / 2, y + h / 2);
}