0

I am working on a project. In this project, I must have a shop that has a huge list of cards. I am also very new to JavaFX.

I made a custom class that inherits pane. It has an image view and some labels to show the name and description of card.

Know my problem is that how should I add them to scene to have an scrollable list of this items? What Components should my Scene have. (I omitted imports in the code below)

CardView.java ---- Custom component that loads an fxml

public class CardView extends Pane {
    CardController cardController;
    Node view;

    public CardView() {

        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../FXMLFiles/Card.fxml"));
        fxmlLoader.setControllerFactory(new Callback<Class<?>, Object>() {
            @Override
            public Object call(Class<?> param) {
                return cardController = new CardController();
            }
        });
        try {
            view = (Node) fxmlLoader.load();

        } catch (IOException ex) {
        }
        getChildren().add(view);
        cardController.setNameAndDsc("Card", "This is A card", heroImg);
    }

}

CardController.java

public class CardController {
    @FXML
    private Label name_lbl;

    @FXML
    private Label dsc_lbl;

    @FXML
    private ImageView card_img;


    public void setNameAndDsc(String name, String dsc, Image img) {
        name_lbl.setText(name);
        dsc_lbl.setText(dsc);
        card_img.setImage(img);
    }

    public void setName_lbl(Label name_lbl) {
        this.name_lbl = name_lbl;
    }

    public void setDsc_lbl(Label dsc_lbl) {
        this.dsc_lbl = dsc_lbl;
    }

    public void setCard_img(ImageView card_img) {
        this.card_img = card_img;
    }
}

Card.fxml

Overall View of Card.fxml: enter image description here

Actually I want to have a huge list of this card that can be scrolled. How should I do that? What Components should I use. I must also note that I have access to JFoenix.

amir na
  • 217
  • 1
  • 13

1 Answers1

1

Use a listview. It's a virtual control so it only creates nodes that are in the visual bounds.

You can apply css to make background transparent.

jpell
  • 198
  • 2
  • 10