Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8115826

ComboBox doesn't align properly with baseline

XMLWordPrintable

      Using a ComboBox in a VBox with baseline alignment produces incorrect alignment. It also causes additional space to show up below the parent node.

      Run the provided test case. Notice that the ChoiceBox is better aligned with the other controls than the ComboBox. Also notice the odd additional space that appears at the bottom of the ComboBox stage (under the second label). This extra space also disappears if you don't set the HBox alignment to baseline.

      **************************************************************

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ChoiceBox;
      import javafx.scene.control.ComboBox;
      import javafx.scene.control.Label;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;


      public class GridPaneTest extends Application {

      @Override public void start(final Stage primaryStage) throws Exception {

      {
             ChoiceBox<String> combo =
             new ChoiceBox<>(FXCollections.observableArrayList("ChoiceBox"));
             combo.getSelectionModel().select(0);
             HBox hbox = new HBox(10, new Label("label:"), combo,
             new Button("Button"));
             hbox.setAlignment(Pos.BASELINE_LEFT);
             VBox vbox = new VBox(30, hbox, new Label("label at bottom"));
            
             primaryStage.setScene( new Scene(vbox) );
            
             primaryStage.sizeToScene();
             primaryStage.centerOnScreen();
            
             primaryStage.show();
      }

      Stage secondStage = new Stage();
      {
             ComboBox<String> combo =
             new ComboBox<>(FXCollections.observableArrayList("ComboBox"));
             combo.getSelectionModel().select(0);
             HBox hbox = new HBox(10, new Label("label:"), combo,
             new Button("Button"));
             hbox.setAlignment(Pos.BASELINE_LEFT);
             VBox vbox = new VBox(30, hbox, new Label("label at bottom"));
            
             secondStage.setScene( new Scene(vbox) );
            
             secondStage.sizeToScene();
             secondStage.centerOnScreen();
            
             secondStage.show();
      }

      }

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

      }

            jgiles Jonathan Giles
            csmithjfx Charles Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: