Skip to content

Commit 4c98329

Browse files
committed
fix results display
1 parent 16161d5 commit 4c98329

2 files changed

Lines changed: 24 additions & 23 deletions

File tree

javafx/src/main/java/com/baeldung/view/SearchController.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import javafx.scene.control.*;
1111
import javafx.scene.input.KeyCode;
1212
import javafx.scene.layout.VBox;
13+
import javafx.scene.control.cell.PropertyValueFactory;
1314

1415
import java.util.stream.Collectors;
1516

@@ -22,11 +23,14 @@ public class SearchController {
2223
@FXML
2324
private Button searchButton;
2425
@FXML
25-
private Pagination pagination;
26-
@FXML
2726
private Label searchLabel;
28-
27+
@FXML
28+
private TableView tableView;
29+
@FXML
30+
private VBox dataContainer;
31+
2932
private ObservableList<Person> masterData = FXCollections.observableArrayList();
33+
private ObservableList<Person> results = FXCollections.observableList(masterData);
3034

3135
public SearchController() {
3236
masterData.add(new Person(5, "John", true));
@@ -52,22 +56,21 @@ private void initialize() {
5256
searchLabel.setText(newValue);
5357
});
5458

55-
pagination.setPageFactory(SearchController.this::createPage);
56-
}
59+
initTable();
5760

58-
private Node createPage(Integer pageIndex) {
59-
60-
VBox dataContainer = new VBox();
61+
}
6162

62-
TableView<Person> tableView = new TableView<>(masterData);
63+
private void initTable() {
64+
tableView = new TableView<>(FXCollections.observableList(masterData));
6365
TableColumn id = new TableColumn("ID");
66+
id.setCellValueFactory(new PropertyValueFactory("id"));
6467
TableColumn name = new TableColumn("NAME");
68+
name.setCellValueFactory(new PropertyValueFactory("name"));
6569
TableColumn employed = new TableColumn("EMPLOYED");
70+
employed.setCellValueFactory(new PropertyValueFactory("isEmployed"));
6671

6772
tableView.getColumns().addAll(id, name, employed);
6873
dataContainer.getChildren().add(tableView);
69-
70-
return dataContainer;
7174
}
7275

7376
private void loadData() {
@@ -86,11 +89,10 @@ protected ObservableList<Person> call() throws Exception {
8689
};
8790

8891
task.setOnSucceeded(event -> {
89-
masterData = task.getValue();
90-
pagination.setVisible(true);
91-
pagination.setPageCount(masterData.size() / PAGE_ITEMS_COUNT);
92+
results = task.getValue();
93+
tableView.setItems(FXCollections.observableList(results));
9294
});
93-
95+
9496
Thread th = new Thread(task);
9597
th.setDaemon(true);
9698
th.start();

javafx/src/main/resources/SearchController.fxml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
<Label fx:id="searchLabel"/>
2121
</children>
2222
</HBox>
23-
24-
<Pagination fx:id="pagination"
25-
AnchorPane.leftAnchor="10.0"
26-
AnchorPane.rightAnchor="10.0"
27-
AnchorPane.topAnchor="50.0"
28-
visible="false">
29-
30-
</Pagination>
23+
24+
<VBox fx:id="dataContainer"
25+
AnchorPane.leftAnchor="10.0"
26+
AnchorPane.rightAnchor="10.0"
27+
AnchorPane.topAnchor="50.0">
28+
29+
</VBox>
3130

3231
</children>
3332
</AnchorPane>

0 commit comments

Comments
 (0)