root.getChildren().addAll(new TreeItem<>("Layout"), new TreeItem<>("is not"), new TreeItem<>("easy")); TreeView<String> notes = new TreeView<>(root); optionPane.getChildren().addAll(menuBar, new Label("Kaiser Notes"), notes); optionPane.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;"); TextField textField = new TextField(); editorBox.getChildren().addAll(textField, editor); editorBox.setStyle("-fx-background-color: mistyrose; -fx-padding: 10;"); layout.setLeft(optionPane); layout.setCenter(editorBox); stage.setScene(new Scene(layout)); stage.show();
import java.util.regex.Pattern; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.stage.Stage; public class NumericTextFieldTest extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) { TextField numberField = new TextField() { @Override public void replaceText(int start, int end, String text) { if (text.matches("[0-9]*")) { super.replaceText(start, end, text); } } @Override public void replaceSelection(String text) { if (text.matches("[0-9]*")) { super.replaceSelection(text); } } }; stage.setScene(new Scene(numberField)); stage.show(); } }
// t is an instance of Template final Map<String,String> params = t.getParameters(); Iterator<Map.Entry<String,String>> it = params.entrySet().iterator(); Map.Entry<String,String> param; int i; for (i=0, param = it.hasNext() ? it.next() : null ; param != null ; i++, param = it.hasNext() ? it.next() : null) { Label label = new Label(); TextField field = new TextField(param.getValue()); final String key = param.getKey(); field.textProperty().addListener((ObservableValue<? extends String> obs, String oldValue, String newValue) -> params.put(key,newValue)); // unrelevant code }
long runningTotal = 0; Button plusButton = new Button("+"); Button enterButton = new Button("Enter"); TextField tf = new TextField(); Label displayLabel = new Label(); //Setup you UI here plusButton.setOnAction(event -> { String stringValue = tx.getText(); long value = Long.parseLong(stringValue); runningTotal = runningTotal + value; }); enterButton.setOnAction(event -> { //if you need to remember your last pressed button, you could have done that also, then perform that action here displayLabel.setText("" + runningTotal); });
class CreateStage { private TextField textBox ; public CreateStage() { textBox = new TextField(); StackPane root = new StackPane(); root.getChildren().add(textBox); Scene scene = new Scene(root, 300, 250); Stage stage = new Stage(); stage.setTitle("Additional Stage"); stage.setScene(scene); stage.initModality(Modality.APPLICATION_MODAL); stage.showAndWait(); } public String getText() { return textBox.getText(); } }
final TextField userText = new TextField(); somePanel.add(userText); //attach the text field to the scene. final Button b = new Button(); somePanel.add(b); // attach the button to desired node in the scene b.setOnAction(event -> { // Here you call the method with the desired logic, // i suppose you have a text field where the user writes his input, in this case caled userText String text = userText.getText(); // from here you have the text and you are able to use your scanner logic });
textField = new TextField(); t.set(editedObject, textField.getText()); System.out.println(editedObject + " for " + textField + " value " + textField.getText()); } catch (IllegalAccessException e) { e.printStackTrace(); listView.setCellFactory(p -> new MyListCell(testObject)); stage.setScene(new Scene(listView)); stage.show();
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class EmbeddedSample extends Application { @Override public void start(Stage stage) { stage.setScene(new Scene(new StackPane(new TextField("xyzzy")), 200, 100)); stage.getScene().setOnMouseClicked(e -> stage.hide()); stage.show(); } public static void main(String[] args) { launch(args); } }
TextField firstNameFld = new TextField(); firstNameFld.setPrefColumnCount(8); TextField lastNameFld = new TextField(); lastNameFld.setPrefColumnCount(8); GridPane grid = new GridPane(); grid.addRow(0, new Label("First Name:"), firstNameFld); grid.addRow(1, new Label("Last Name:"), lastNameFld); tp1.setContent(grid); tp2.setContent(new Label("tp2.............")); tp3.setContent(new Label("tp3.............."));
TextField fileInput = new TextField(); Button inputButton = new Button("Upload File"); inputButton.disableProperty().bind(Bindings.createBooleanBinding( () -> ! new File(fileInput.getText()).exists(), fileInput.textProperty())); inputButton.setOnAction(e -> { inputFile = new File(fileInput.getText()); window.close(); });
TextField txt = new TextField("textComponent"); txt.setOutputMarkupId(true); txt.setMarkupId("someId"); // Make sure it is unique in the page Button b = new Button("buttonComponent"); b.add(new SimpleAttributeModifier("onclick", "makeRequest('" + txt.getMarkupId() + "','GET', null, null,'CLICKSTREAM'")); add(txt); add(b);
TextField tfPost = new TextField("140 character word count..."); Button btTweet = new Button("Tweet"); TweetHandlerClass btTweetHandler = new TweetHandlerClass(tfPost); btTweet.setOnAction(btTweetHandler);
public void start(Stage stage) { final Person aPerson = new Person("Fred", false, false, "Much Ado About Nothing"); final Label currentObjectValue = new Label(aPerson.toString()); TableView<NamedProperty> table = new TableView(); table.setEditable(true); stage.setScene(scene); stage.show(); textField = new TextField(getString()); textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2); textField.focusedProperty().addListener(new ChangeListener<Boolean>() { public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (!newValue) { commitEdit(textField.getText());
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class TextFieldCssSample extends Application { @Override public void start(Stage stage) throws Exception { TextField textField = new TextField(); textField.setId("textField"); StackPane layout = new StackPane(); layout.getChildren().addAll(textField); layout.getStylesheets().add(this.getClass().getResource("textfield.css").toExternalForm()); stage.setScene(new Scene(layout)); stage.show(); } public static void main(String[] args) { launch(args); } }