import com.sun.javafx.runtime.VersionInfo; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.HBox; import javafx.scene.text.Font; import javafx.stage.Stage; import javafx.util.Callback; public class ComboBoxCellHeightSample extends Application { ComboBox comboBox; final static int INITIAL_FONT_SIZE = 8; final static int MAX_FONT_SIZE = 36; public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { stage.setTitle(VersionInfo.getRuntimeVersion()); Scene scene = createScene(); // System.setProperty("http.proxyHost", "www-proxy.uk.oracle.com"); // System.setProperty("http.proxyPort", "80"); // scene.getStylesheets().add(ComboBoxCellHeightSample.class.getResource("font.css").toExternalForm()); stage.setScene(scene); stage.show(); } private Scene createScene() { HBox root = new HBox(4); comboBox = new ComboBox(); root.getChildren().add(comboBox); Button populateComboBoxWithFontSizes = new Button("Populate ComboBox with font sizes"); populateComboBoxWithFontSizes.setOnAction(new EventHandler() { public void handle(ActionEvent t) { comboBox.setCellFactory(new Callback, ListCell>() { @Override public ListCell call(ListView p) { return new ListCell() { { setContentDisplay(ContentDisplay.TEXT_ONLY); } @Override protected void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setText(null); } else { setText(item); setFont(new Font(Double.valueOf(item))); } } }; } }); for (int i = INITIAL_FONT_SIZE; i <= MAX_FONT_SIZE; i += 2) { comboBox.getItems().add(String.valueOf(i)); } } }); root.getChildren().add(populateComboBoxWithFontSizes); return new Scene(root, 400, 300); } }