Set JavaFx ComboBox Font?

combobox, fonts, javafx-2

Solution

I think there is no way to do it without CSS. You can assign the style to that component as in the next sample:

VBox vbox = new VBox(10);
vbox.setAlignment(Pos.CENTER_LEFT);

ComboBox<String> noStyled = new ComboBox<>();
noStyled.getItems().addAll("One", "Two", "Three");

ComboBox<String> styled = new ComboBox<>();
styled.setPrefWidth(150);
styled.getItems().addAll("One", "Two", "Three");
styled.setStyle("-fx-font: 30px \"Serif\";");

vbox.getChildren().addAll(noStyled, styled);
Scene scene = new Scene(vbox);
stage.setScene(scene);
stage.show();

Or you can assign a stylesheet to an application. In both cases I recommend you to go through the tutorial CSS Section in the oracle web site and the reference guide.

Hope it helps.

Problem

Im trying to change a ComboBox Font on JavaFx, so I have: `ComboBox cbCategoria = new ComboBox();` Im new in javaFx so some example code would be great :D, Is a Way to do it without CSS? and if not how can i make it with CSS,I havent learned how to use CSS Styling yet :(

Original source