Let only one control grow in a HBox : HBox « JavaFX « Java






Let only one control grow in a HBox

 

import javafx.application.Application;
import javafx.scene.Group;
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.Priority;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Main extends Application {
  public static void main(String[] args) {
    Application.launch(args);
  }

  @Override
  public void start(Stage primaryStage) {
    primaryStage.setTitle("");
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);

    HBox hbox = new HBox();
    TextField field = new TextField();
    HBox.setHgrow(field, Priority.ALWAYS);
    hbox.getChildren().addAll(new Label("Search:"), field, new Button("Go"));

    
    root.getChildren().add(hbox);
    primaryStage.setScene(scene);
    primaryStage.show();
  }
}

   
  








Related examples in the same category

1.Grow in HBox
2.Set Preferred Width for HBox
3.Set space between controls for HBox
4.Adding controls to HBox
5.Set Padding and Spacing for HBox