JavaFX Label add label for TextField

Description

JavaFX Label add label for TextField


import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public class Main extends Application {
  @Override//from ww  w  .  ja va  2 s .com
  public void start(Stage primaryStage) {
    // Create a pane and set its properties
    FlowPane pane = new FlowPane();
    pane.setPadding(new Insets(11, 12, 13, 14));
    pane.setHgap(5);
    pane.setVgap(5);

    // Place nodes in the pane
    pane.getChildren().addAll(new Label("First Name:"), 
      new TextField(), new Label("MI:"));
    
    TextField tfMi = new TextField();
    tfMi.setPrefColumnCount(1);
    
    pane.getChildren().addAll(tfMi, new Label("Last Name:"),
      new TextField());
    

    Scene scene = new Scene(pane, 550, 120);
    primaryStage.setTitle("ShowFlowPane");
    primaryStage.setScene(scene);
    primaryStage.show();
  }
  

  public static void main(String[] args) {
    launch(args);
  }
}



PreviousNext

Related