- TableView 페이징
- TableView 순번 역순으로 표시하기
- TableView 컬럼 테이블에 100% 적용하기
- TableView 컬럼 정렬 틀어지는 버그 수정
setColumnSize() 에서 컬럼의 너비를 테이블에 100%로 맞춘다.
이럴 경우 스크롤이 생길 때 테이블의 컬럼 헤더부분과 바디부분의 정렬이 틀어지게 된다.
그래서 데이터조회 후 테이블에 데이터를 넣고 table.refresh() 로 테이블을 refresh 해준다.
Platform.runLater(() -> { table.refresh(); });
넘버링을 순차적으로 하려면
col1.setCellValueFactory(param -> new ReadOnlyObjectWrapper<Number>(table.getItems().indexof(param.getValue()) + 1));
넘버링을 데이터 갯수의 역수로 보여주려면
col1.setCellValueFactory(param -> new ReadOnlyObjectWrapper<Number>(totalCount - (pageSize * pageIndex) - table.getItems().indexOf(param.getValue())));
private Page page;
private int totalCount = 0;
private int pageIndex = 0;
private int pageSize = 10;
@FXML private TableView<UserVO> table;
@FXML private TableColumn<UserVO, Number> col1;
@FXML private TableColumn<UserVO, String> col2;
// 초기화
public void initialize(URL location, ResourceBundle resources) {
totalCount = service.getTotalCount();
page = new Page((totalCount == 0 ? 1 : totalCount), pageSize);
page.getPagination().setPageFactory(this::createData);
AnchorPane.setLeftAnchor(page.getAnchor(), 0.0);
AnchorPane.setRightAnchor(page.getAnchor(), 0.0);
table.getChildren().add(page.getAnchor());
}
private Node createData(int pageIndex) {
tableSetting();
this.pageIndex = pageIndex;
page.setSelectedPage(pageIndex);
....
Platform.runLater(() -> {
table.refresh();
});
}
private void tableSetting() {
col1.setCellValueFactory(param -> new ReadOnlyObjectWrapper<Number>(totalCount - (pageSize * pageIndex) - table.getItems().indexOf(param.getValue())));
col2.setCellValueFactory(param -> new SimpleStringProperty(param.getValue()));
}
private void setColumnSize() {
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
col1.setMaxWidt(1f * Integer.MAX_VALUE * 50);
col2.setMaxWidt(1f * Integer.MAX_VALUE * 50);
}
public class Page extends Pagination {
private Pagination pagination;
private AnchorPane anchor;
private int totalPage;
private int selectedPage = 0;
private int rowsPerPage = 10;
public Page() {
pagination = new Pagination();
}
public Page(int totalCount, int rowsCount) {
rowsperPage = rowsCount;
totalPage = totalCount / rowsPerPage;
totalPage = totalCount % rowsPerPage > 0 ? ++totalPage : totalPage;
pagination = new Pagination(totalPage, 0);
createAnchorPane();
}
public void createAnchorPane() {
anchor = new AnchorPane();
AnchorPane.setLeftAnchor(pagination, 0.0);
AnchorPane.setRightAnchor(pagination, 0.0);
AnchorPane.setTopAnchor(pagination, 0.0);
AnchorPane.setBottomAnchor(pagination, 0.0);
anchor.getChildren().addAll(pagination);
AnchorPane.setTopAnchor(anchor, 0.0);
AnchorPane.setBottomAnchor(anchor, 0.0);
}
public void setSelectedPage(int selectedpage) {
this.selectedPage = selectedPage;
}
}
'JavaFX' 카테고리의 다른 글
[Java] SWT Table multi 테이블 다중선택 (0) | 2022.08.09 |
---|---|
[JavaFX] KeyCode.ESCAPE esc 단축키 사용하기 (0) | 2020.09.18 |
[JavaFX] MenuItem setMnemonicParsing 단축키, SeparatorMenuItem 구분자 (0) | 2020.08.28 |
[JavaFX] multiple key event Combination ctrl + s 단축키 사용 (0) | 2020.08.25 |
[JavaFX] TreeTableView Key event - Row Delete (0) | 2020.08.20 |