package fx01;
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.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class pro extends Application {
@Override
public void start(Stage primaryStage) {
final TextField tf = new TextField();
tf.setPrefColumnCount(15);
tf.setTooltip(new Tooltip("文字を入力して下さい"));
Button btn = new Button();
btn.setText("確定");
btn.setDefaultButton(true);
btn.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
if (tf.getText() != null && !tf.getText().isEmpty()) {
System.out.println(tf.getText());
}
}
});
HBox hb = new HBox();
hb.getChildren().addAll(tf, btn);
hb.setSpacing(2);
StackPane root = new StackPane();
root.getChildren().add(hb);
Scene scene = new Scene(root);
primaryStage.setTitle("Sample_TextField");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}