Use CSS
.combo-box {
-fx-pref-width: 100;
}
.combo-box-popup > .list-view {
-fx-pref-width: 100;
}
Note. I tested this example only in Java 8, and I believe that attributes -fx-*-widthand -fx-*-heightcss may be new to JavaFX 8.
Usage example
In this example, both the list and drop-down buttons were designed for the same preferred width (100 pixels).

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class SizedComboBoxSampleWithCss extends Application {
public static void main(String[] args) { launch(args); }
@Override public void start(Stage stage) {
final ComboBox<String> combo = new ComboBox<>();
combo.setValue(Font.getDefault().getFamily());
combo.getItems().setAll(Font.getFamilies());
combo.getStylesheets().add(
getClass().getResource(
"combo-size.css"
).toExternalForm()
);
StackPane layout = new StackPane(combo);
layout.setPadding(new Insets(10));
stage.setScene(new Scene(layout));
stage.show();
}
}
source
share