JavaFX制作一个项目网格

时间:2017-12-28 17:55:21

标签: java gridview javafx

我正在使用一系列项目,我希望在JavaFX中以网格的形式显示,就像在MS Word中完成的那样enter image description here

在Android中我们有一个RecyclerView可以是listviewgridview,具体取决于布局管理器集,JavaFX中有这样的东西吗?我找不到关于如何制作gridview的教程,如果有人有想法请分享 下面是我想要显示为网格单元格的单元格

public class TicketCell extends ListCell<Ticket> { 
private static final String TAG = TicketCell.class.getSimpleName();
private Logger logger;
private Ticket ticket;
@FXML
private Label lbDescription;
@FXML
private HBox parent;  
@FXML
private ImageView imgTicketImage;
private FXMLLoader mLLoader;


  public TicketCell(){
    logger = Logger.getLogger(MainWindowController.class);
    BasicConfigurator.configure(); 
  if (mLLoader == null) {
            mLLoader = new FXMLLoader(getClass().getResource("/resources/fxml/TicketDesignCell.fxml"));
            mLLoader.setController(this);

            try {
                mLLoader.load();
            } catch (IOException e) {
                logger.error(TAG, e);
            }

}
}


public void updateItem(Ticket pos,boolean empty){
super.updateItem(pos, empty);

if(pos == null){
setText(null);
setGraphic(null);
}else{




    this.lbDescription.setText(pos.getDescription());
    this.imgTicketImage.setCache(true);
    this.imgTicketImage.setSmooth(true);
    this.imgTicketImage.setImage(new Image(pos.getImageUrl()));



    setText(null);
    setGraphic(parent);


}

}

以及我如何使用它

public class MainWindowController implements Initializable, EventHandler<ActionEvent> {

private static final String TAG = MainWindowController.class.getSimpleName();
private JFXListView lsTicketDesign;
private ObservableList<Ticket> ticketDesignList = FXCollections.observableArrayList();
private Stage stage;

public void setMyStage(Stage myStage) {
    this.stage = myStage;


}

@Override
public void initialize(URL url, ResourceBundle rb) {
    this.tabPane.prefWidthProperty().bind(anchorPane.widthProperty());
    this.tabPane.prefHeightProperty().bind(anchorPane.heightProperty());
    logger = Logger.getLogger(MainWindowController.class);
    ticketDesignList.add(new Ticket(1, "resources/images/template_01.png",  "Basic ticket template"));
    lsTicketDesign.setItems(ticketDesignList);
    lsTicketDesign.autosize();
    lsTicketDesign.setCellFactory(ticketDesignList -> new  TicketCell()); 

    lsTicketDesign.getSelectionModel().selectedItemProperty().addListener(new ChangeListenerImpl());

} 

0 个答案:

没有答案
相关问题