/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package test; import com.javafx.experiments.scenicview.ScenicView; import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.HBox; import javafx.scene.layout.HBoxBuilder; import javafx.scene.layout.StackPane; import javafx.stage.Stage; import javafx.util.Callback; /** * * @author fabriceb */ public class Main extends Application { /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } private static class StringListCell extends ListCell { Label label = LabelBuilder.create().id("label").build(); public StringListCell() { super(); HBox box = HBoxBuilder.create().id("rendererHBox").alignment(Pos.BOTTOM_RIGHT).children(label).build(); setGraphic(box); } @Override protected void updateItem(String value, boolean empty) { super.updateItem(value, empty); label.setText(value); } } @Override public void start(Stage primaryStage) { ComboBox combo = ComboBoxBuilder.create().build(); combo.getItems().addAll("1", "2", "3", "4", "5", "A long label"); // Uncomment this for FX 2.2. combo.setButtonCell(new StringListCell()); combo.setCellFactory(new Callback, ListCell>() { @Override public ListCell call(ListView arg0) { return new StringListCell(); } }); StackPane root = new StackPane(); root.getChildren().add(combo); Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Test_ComboBox"); primaryStage.setScene(scene); primaryStage.show(); ScenicView.show(scene); } }