【问题标题】:Is there a CheckBoxListCell equivalent for JFoenix so that we can use JFXCheckBox instead of the traditional one?是否有与 JFoenix 等效的 CheckBoxListCell 以便我们可以使用 JFXCheckBox 而不是传统的?
【发布时间】:2018-06-27 18:57:21
【问题描述】:

所以我目前正在使用我的 JFXListView 并尝试使用 CheckBoxListCell 在其中设置几个复选框。原来我用这个:

listView.setCellFactory(CheckBoxListCell.forListView(new Callback<classForMenuOptions, ObservableValue<Boolean>>() {
            @Override
            public ObservableValue<Boolean> call(UserMenuOptions item) {
                return item.selectedProperty();
            }
}));

有没有办法让我可以使用 JFXCheckBox 代替传统的 CheckBox?

【问题讨论】:

  • JFoenix 有可怕的文档,但是您是否尝试过查看 JFXCheckBox 是如何实现的?可能有一些方法可以扩展它的用途。
  • 正如@Zephyr 指出的那样,JFoenix 的文档非常糟糕。查看 Javadoc(我无法在网上找到,必须从 Maven 下载)似乎没有任何内置单元用于此。您必须以Sedrick does in his answer 的身份在细胞工厂中创建自己的细胞。您可以通过查看CheckBoxListCell is implemented in JavaFX 获得更多灵感(如果需要)。

标签: java javafx jfoenix


【解决方案1】:

你基本上只需要实现你自己的cellFactory

import com.jfoenix.controls.JFXCheckBox;
import com.jfoenix.controls.JFXListView;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ListCell;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class ListViewExperiments extends Application
{

    @Override
    public void start(Stage primaryStage) throws Exception
    {
        primaryStage.setTitle("ListView Experiment 1");

        JFXListView<String> listView = new JFXListView<>();
        listView.setPrefWidth(200);
        listView.setCellFactory(lv -> new ListCell<String>()
        {
            JFXCheckBox checkBox = new JFXCheckBox();

            @Override
            public void updateItem(String item, boolean empty)
            {
                super.updateItem(item, empty);
                if (empty) {
                    //setText(null);
                    setGraphic(null);
                }
                else {
                    checkBox.setText(item);
                    setGraphic(checkBox);
                }
            }
        });
        listView.getItems().add("Item 1");
        listView.getItems().add("Item 2");
        listView.getItems().add("Item 3");

        HBox hbox = new HBox(listView);

        Scene scene = new Scene(hbox, 300, 120);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

【讨论】:

    猜你喜欢
    • 2011-01-22
    • 1970-01-01
    • 2020-02-22
    • 2018-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多