enter image description here

Is it possible to somehow align the contents? Or just need to create a tableView?

  • There are three labels without a fixed size, and the string itself HBox? - Maxim
  • @Maxim above, yes, and everything else is displayed simply in the listView - Eduard Farkhutdinov
  • And, you have a standard cell implementation. You need to make your own complex cell, but you can immediately move the delete and clear buttons to it. turais.de/how-to-custom-listview-cell-in-javafx - Maxim
  • @Maxim I need the data to be displayed in the listView exactly. And not as on the screen. Is it possible in Listview? - Edward Farhutdinov
  • Yes, you need to make in the listView a composite cell that you can impose as you like (for example, how you made the header). A cell in the listView is made up in the same way as the layout of the application. - Maxim

1 answer 1

A simple example:

import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.ContentDisplay; import javafx.scene.control.Label; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception { ListView<DirectoryInfo> listView = new ListView<>(); listView.getItems().addAll( new DirectoryInfo("Курсовая работа", 6, 275), new DirectoryInfo("ЧисленныеМетоды", 4, 0), new DirectoryInfo("Политология", 1, 543), new DirectoryInfo("Матанализ", 1, 100), new DirectoryInfo("ООП", 3, 1753) ); listView.setCellFactory(param -> new DirectoryInfoListCell()); primaryStage.setScene(new Scene(listView,300, 300)); primaryStage.show(); } private static class DirectoryInfo { public DirectoryInfo(String directory, int countFiles, double size) { this.directory = directory; this.countFiles = countFiles; this.size = size; } String directory; int countFiles; double size; } private static class DirectoryInfoListCell extends ListCell<DirectoryInfo> { private Label lDirectory; private Label lCountFiles; private Label lSize; private HBox hbContent; public DirectoryInfoListCell() { setContentDisplay(ContentDisplay.GRAPHIC_ONLY); } @Override protected void updateItem(DirectoryInfo item, boolean empty) { super.updateItem(item, empty); if (empty) { setGraphic(null); } else { if (hbContent == null) { initContent(); } lDirectory.setText(item.directory); lCountFiles.setText(String.valueOf(item.countFiles)); lSize.setText(String.valueOf(item.size)); setGraphic(hbContent); } } private void initContent() { lDirectory = new Label(); lDirectory.setMinWidth(150); lCountFiles = new Label(); lCountFiles.setMinWidth(100); lSize = new Label(); lSize .setMinWidth(100); hbContent = new HBox(lDirectory, lCountFiles, lSize); } } }