-fx-selection-bar-text
이 Scene
의 선택입니다 루트 기본 CSS 선택기에 정의 된 컬러 팔레트 (안 CSS 속성)이다 :이 RoomCell 구현입니다. 당신이 그것을 사용하는 방법을 모르겠어요하지만 당신처럼 (이 장면의 선택이다 세계적 이후)을 정의하는 경우 : CSS 파일에
.root{
-fx-selection-bar-text: red;
}
다음 -fx-selection-bar-text
를 사용하여 모든 컨트롤 'CSS 속성은 빨간색으로 표시됩니다. ListView
도 영향을받습니다 (아래에서 원래 사용법에 대한 설명 참조).
그러나 당신 만의 ListView의 스타일을 사용자 정의 기본 속성을
(참고 : -fx-text-fill
-fx-selection-bar-text
가 사용되는 경우 원래 값은, 주석 처리되어 오버라이드 (override)합니다.) :이 방법을 무시하려는 경우
/* When the list-cell is selected and focused */
.list-view:focused .list-cell:filled:focused:selected {
-fx-background-color: -fx-focus-color, -fx-cell-focus-inner-border, -fx-selection-bar;
-fx-background-insets: 0, 1, 2;
-fx-background: -fx-accent;
/* -fx-text-fill: -fx-selection-bar-text; */
-fx-text-fill: red;
}
/* When the list-cell is selected and selected-hovered but not focused.
Applied when the multiple items are selected but not focused */
.list-view:focused .list-cell:filled:selected, .list-view:focused .list-cell:filled:selected:hover {
-fx-background: -fx-accent;
-fx-background-color: -fx-selection-bar;
/* -fx-text-fill: -fx-selection-bar-text; */
-fx-text-fill: green;
}
/* When the list-cell is selected, focused and mouse hovered */
.list-view:focused .list-cell:filled:focused:selected:hover {
-fx-background: -fx-accent;
-fx-background-color: -fx-focus-color, -fx-cell-focus-inner-border, -fx-selection-bar;
-fx-background-insets: 0, 1, 2;
/* -fx-text-fill: -fx-selection-bar-text; */
-fx-text-fill: yellow;
}
이 CSS를 특성 및 더 많은 것은 붙박이 caspian.css에서 유효하다.
업데이트 : 난 강력하게 당신이 Cell API를 읽고 조언. 거기에서
... 우리는 극소수의 셀만 사용하여 매우 큰 데이터 세트를 나타냅니다. 각 셀을 "재활용"하거나 다시 사용합니다.
다른 문자열 항목은 코드에서 isSelected()
과 같은 오해의 소지가있는 시각 효과/렌더링으로 끝나는 동일한 셀을 사용할 수 있습니다. 세포의 가장 일반적인 사용은 사용자에게 텍스트를 표시하는 것입니다 지금까지이 사용 사례 특별히 셀 내에서 최적화되어 있기 때문에 또한 API에서이
을 말한다. 이것은 입니다. Cell은 Labeled에서 확장했습니다. 즉, Cell의 하위 클래스는 별도의 Label을 만들고 Cell 내에서 설정하기보다는 텍스트 속성 만 설정하면됩니다.다음과 같이
그래서 난 당신의 코드를 리팩토링.
class RoomCell extends ListCell<String> {
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
Log.debug("RoomCell called, item: "+item);
setFont(Font.font("Segoe UI", FontWeight.BOLD, 18));
ImageView iView = new ImageView();
if (Rooms.getBoolean(item, "OwnerStatus")) {
iView.setEffect(new DropShadow(15, Color.BLUEVIOLET));
iView.setImage(new Image(getClass().getResourceAsStream("images/universal.png")));
} else {
iView.setEffect(new DropShadow(15, Color.WHITE));
iView.setImage(new Image(getClass().getResourceAsStream("images/yin-yang.png")));
}
setGraphic(iView); // The image will be displayed here
setText(item); // The room name will be displayed here
}
}
}
모두 -fx-text-fill
CSS 파일의 정의에 따라 셀의 텍스트 스타일이 변경됩니다.
여기에서 지금은 트레이드 오프 셀의 텍스트의 DropShadow 효과와 CSS 파일에서의 채우기 색상 간의이다 :
- 당신의 DropShadow 효과를 사용하려면, 현재의 방법, 즉, 라벨을 만들어 해당 텍스트를 설정처럼 이동해야 할 경우 , 레이블 및 setGraphic (레이블)에 dorpshadow 효과를 부여하십시오. 그러나 이번에는 셀의 텍스트 (setText(item)
)를 설정하는 것을 선호하지 않으므로 CSS 파일의 텍스트 색상 스타일은 아무 효과가 없습니다.
- 반면에, 당신은 내가 할 CSS 파일에 DropShadow를 위해, 당신은 transparent
또는 null
으로 설정하여 (Labeled
을 확장) 세포의 -fx-background-color
을 비활성화하고 -fx-effect
을 설정하려면해야 리팩토링 한 코드를 선호하는 경우 텍스트에 드롭 섀도우 효과를 직접 적용 할 수 있습니다. 세포의 배경을 지우는 것이 선호되는 방법이 아닙니다. 코드에 따른 설명 :
Label lbl = new Label("This text will have a dropshadow on itself directly");
lbl.setEffect(new DropShadow(15, Color.BLUE));
Label another_lbl = new Label("This text will have a dropshadow applied on the background bounds, not to text");
another_lbl.setEffect(new DropShadow(15, Color.BLUE));
another_lbl.setStyle("-fx-background-color:gray");
차이점을 확인하려면 테스트하십시오. 그게 다야.
감사합니다 ... 저를 도왔! – Vikram