Monday, March 26, 2012

JavaFX 2.0 - TextField

JavaFX 2.0 - TextField
package javafx_ui;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
*
* @web http://java-buddy.blogspot.com/
*/
public class JavaFX_TextField extends Application {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("java-buddy.blogspot.com");

Label label1 = new Label("TextField:");

final TextField textField = new TextField ();
textField.setPromptText("Enter something here...");
textField.setPrefColumnCount(15);

final Label label = new Label("hello...");

Button buttonEnter = new Button("Enter");
buttonEnter.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent arg0) {
label.setText(textField.getText());
}
});

HBox hBox = new HBox();
hBox.getChildren().addAll(label1, textField, buttonEnter);
hBox.setSpacing(10);
hBox.setMaxHeight(25);

VBox vBox = new VBox();
vBox.getChildren().addAll(hBox, label);

StackPane root = new StackPane();
root.getChildren().add(vBox);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}

No comments:

Post a Comment