我遇到了一个我无法解决的问题。我想实施进度条设置为组合框:setButtonCell for ComboBox
public class JavaFXApplication4 extends Application
{
@Override
public void start(Stage primaryStage)
{
double y1 = 15;
ProgressBar p1 = new ProgressBar();
p1.setLayoutY(y1);
HBox vb1 = new HBox(10);
vb1.getChildren().addAll(new Label("Progressbar 1"), p1);
double y2 = 15;
ProgressBar p2 = new ProgressBar();
p2.setLayoutY(y2);
HBox vb2 = new HBox(10);
vb2.getChildren().addAll(new Label("Progressbar 2"), p2);
double y3 = 15;
ProgressBar p3 = new ProgressBar();
p3.setLayoutY(y3);
HBox vb3 = new HBox(10);
vb3.getChildren().addAll(new Label("Progressbar 3"), p3);
TextChooser textChooser = new TextChooser(
vb1, vb2, vb3
);
textChooser.setStyle("-fx-font: 10px \"Verdana\";");
StackPane root = new StackPane();
root.getChildren().add(textChooser);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static class TextChooser extends StackPane
{
private Label label = new Label();
private ComboBox<HBox> combo = new ComboBox<>();
public TextChooser(HBox... options)
{
StackPane.setAlignment(label, Pos.CENTER_LEFT);
StackPane.setAlignment(combo, Pos.CENTER_LEFT);
label.graphicProperty().bind(
//combo.getSelectionModel().selectedItemProperty()
combo.getSelectionModel().selectedItemProperty()
);
label.visibleProperty().bind(
combo.visibleProperty().not()
);
//label.setPadding(new Insets(0, 0, 0, 10));
combo.getItems().setAll(options);
combo.setCellFactory(new Callback<ListView<HBox>, ListCell<HBox>>()
{
@Override
public ListCell<HBox> call(ListView<HBox> p)
{
return new ListCell<HBox>()
{
@Override
protected void updateItem(HBox item, boolean empty)
{
super.updateItem(item, empty);
if (item == null || empty)
{
setGraphic(null);
}
else
{
setGraphic(item);
}
}
};
}
});
combo.getSelectionModel().select(0);
combo.setVisible(true);
label.setOnMouseEntered(event -> combo.setVisible(true));
combo.showingProperty().addListener(observable ->
{
if (!combo.isShowing())
{
combo.setVisible(false);
}
});
combo.setOnMouseExited(event ->
{
if (!combo.isShowing())
{
combo.setVisible(false);
}
});
getChildren().setAll(label, combo);
}
public static void main(String[] args)
{
launch(args);
}
}
}
你能告诉我怎么也以进度条显示在组合框中使用setButtonCell
?
是的,它在JavaFX 2.2中工作,但在Java 8中工作不正常。你有什么想法我可以使用'setButtonCell'? –
我得到了这个建议:'你不应该把节点放入物品清单 - 而是应该将数据存储在那里,然后与你的细胞工厂一起渲染。 –