IT 문제해결

JavaFX table checkbox header custom alignment 테이블 헤더 정렬

클레인 2017. 11. 28.
반응형

Java FX 에서 각각의 테이블 헤더마다 정렬을 다르게 주고 싶었지만

Css 로 테이블 헤더의 정렬을 주는 것을 아래와 같지만

.table-view .column-header .label{
-fx-font-size: 12pt;
-fx-font-family: 'Malgun Gothic';
-fx-alignment: center;
}

위와 같이 정렬을 주었을 때는 모든 헤더가 가운데로 정렬이 되기 때문에 각각에 대해 css 를 주기가 쉽지가 않다.

만약 첫번째 열이 체크박스 헤더를 갖고 그 열만 가운데로 위치 시키고 싶어서 아래와 같이 override css 를 적용하기도 쉽지 않을 뿐더러 적용이 되지 않는다.

 

 

.변수명 .table-view .column-header .label{
-fx-font-size: 12pt;
-fx-font-family: 'Malgun Gothic';
-fx-alignment: center-left;
}

 

이와 같이 각각의 헤더에 대해 custom alignment 를 사용하기 위해 결국

코드에서 대한 checkbox 에 대해 css 로 padding 설정을 하여 아래 그림과 같이 checkbox 를 중앙에 위치할 수 있었다.

 

 

 

* code

final CheckBox cb = new CheckBox();
cb.setUserData(tChecked);
cb.setPrefHeight(14);
cb.setMinHeight(14);
cb.getStyleClass().remove("tableHeadercheckbox");
cb.getStyleClass().add("tableHeadercheckbox");
tChecked.setResizable(false);

 

 

 

* Css

.tableHeadercheckbox .check-box {
-fx-padding: 0 0 0 9;
fx-background-repeat: no-repeat ;
}

.tableHeadercheckbox .check-box.check-box:selected {
-fx-padding: 0 0 0 9;
-fx-border-image-repeat: no-repeat ;
-fx-background-repeat: no-repeat ;
-fx-background-image: null;
}

 

 

반응형

댓글