Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.Application;
- import javafx.event.EventHandler;
- import javafx.geometry.Insets;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.layout.VBox;
- import javafx.scene.text.Font;
- import javafx.stage.Stage;
- public class test extends Application {
- public static void main(String[] args) {
- launch(args);
- }
- @Override
- public void start(Stage stage) {
- Scene scene = new Scene(new Group());
- stage.setTitle("TextField Sample");
- stage.setWidth(450);
- stage.setHeight(550);
- final Label label = new Label("click here");
- final TextField temp = new TextField();
- label.setOnMouseClicked(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent arg0) {
- //I put the text
- temp.setText("this is a test");
- //Change the graphic
- label.setGraphic(temp);
- temp.requestFocus();
- // I want the caret to be at the end. In reality it will
- // be but at screen it will be at the beginning the first time.
- temp.end();
- }
- });
- label.setFont(new Font("Arial", 20));
- final VBox vbox = new VBox();
- vbox.setSpacing(5);
- vbox.setPadding(new Insets(10, 0, 0, 10));
- vbox.getChildren().addAll(label);
- ((Group) scene.getRoot()).getChildren().addAll(vbox);
- stage.setScene(scene);
- stage.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement