Increase Combobox text size


Question

I have this basic example of JavaFX combobox:

public class JavaFXComboBox extends Application {

    @Override
    public void start(Stage primaryStage) {

        final ComboBox comboBox = new ComboBox();
        comboBox.getItems().addAll(
                "Item 1",
                "Item 2",
                "Item 3",
                "Item 4");
        comboBox.setValue("Item 1");

        final Label label = new Label();

        Button btn = new Button();
        btn.setText("Read comboBox");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                label.setText("selectd: " + comboBox.getValue());
            }
        });

        VBox vBox = new VBox();
        vBox.setPadding(new Insets(5, 5, 5, 5));
        vBox.setSpacing(5);
        vBox.getChildren().addAll(label, comboBox, btn);

        StackPane root = new StackPane();
        root.getChildren().add(vBox);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

Can you tell me how I can increase the size of the text insight the combox but keeping the original combobox label size?

enter image description here

1
2
12/25/2013 9:22:46 PM

Make a combo.css file like-

.combo-box-popup .list-view {
    -fx-font-size : 15pt;
}

/*added this in an edit*/
.combo-box-popup .list-view .list-cell {
    -fx-padding: -1 -1 -1 -1;
}

and add the line scene.getStylesheets().add("javafxcombobox/combo.css"); after the scene is created.

enter image description here

Some snips from caspian.css will give you things to try. Play with the padding and see what happens.

.combo-box-popup .list-view {
-fx-background-color: -fx-box-border, -fx-control-inner-background;
-fx-background-insets: 0, 1;
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 8, 0.0 , 0 , 0 );
}

.combo-box-popup .list-view .list-cell {
-fx-padding: 4 0 4 5;
-fx-background-color: -fx-control-inner-background;
}

I'd like to know if there's a way to add sub styles in comboBox.setStyle() if anyone knows.

4
12/26/2013 9:02:56 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon