I have this CSS style in my application:
.list-cell {
-fx-background-color: null;
-fx-font-size: 24px;
-fx-text-fill: linear-gradient( from 0.0% 0.0% to 0.0% 50.0%, reflect, rgba(255,0,0,0.28) 0.0, rgba(102,243,255,0.58) 50.0, rgba(179,179,179,0.45) 70.0, rgba(179,179,179,0.45) 100.0);
}
.list-cell:hover {
-fx-text-fill:linear-gradient( from 0.0% 0.0% to 100.0% 100.0%, reflect, rgb(255,255,255) 0.0, rgb(255,255,77) 100.0);
}
And I apply it to my program:
scene.getStylesheets().add(getClass().getResource("/com/root/tomaszm/Design.css").toExternalForm());
And I would like to use this style only for one ListView node not for any other. I have problem that new ComboBox inherit this style.
I know thats probably basic thing but Im not yet familiar with CSS, and just looking for quick fix...
EDIT:
@CHARSET "UTF-8";
#mainList .list-cell {
-fx-background-color: null;
-fx-font-size: 24px;
-fx-text-fill: linear-gradient( from 0.0% 0.0% to 0.0% 50.0%, reflect, rgba(255,0,0,0.28) 0.0, rgba(102,243,255,0.58) 50.0, rgba(179,179,179,0.45) 70.0, rgba(179,179,179,0.45) 100.0);
}
#mainList .list-cell:hover {
-fx-text-fill:linear-gradient( from 0.0% 0.0% to 100.0% 100.0%, reflect, rgb(255,255,255) 0.0, rgb(255,255,77) 100.0);
}
Application class
scene.getStylesheets().add(getClass().getResource("/com/root/tomaszm/Design.css").toExternalForm());
controller class
listView.getStyleClass().add("mainList");
You have to add style class to your ListView
your css
You can read the doc for more explanations http://docs.oracle.com/javafx/2/css_tutorial/jfxpub-css_tutorial.htm
The way you have written your css, you need to set the
css id
to your node and not astyleclass
in your controller.Background
A node can have both
.styleclass {...}
)#id {...}
)From the JavaDocs:
Difference
getStyleClass().add("mainList")
sets thestyleClass
of a node and is used in the css file by declaring :For declaring an id to a node (lets taking your example), you should use :
You use the id as you have already used in the css file:
Note : Do not confuse
id
andfx:id
. Both are used for differently and have different implementations. For more information, click me!