-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcssref.html
More file actions
6199 lines (6171 loc) · 267 KB
/
Copy pathcssref.html
File metadata and controls
6199 lines (6171 loc) · 267 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en-US">
<head>
<meta name="description" content="This document describes the JavaFX
Cascading Style Sheets (CSS) for JavaFX 8 and explains the
styles, values, properties and associated grammar.">
<meta name="keywords" content="JavaFX, JavaFX CSS, JavaFX CSS reference,
JavaFX CSS guide, JavaFX styling, CSS styles, CSS, cascading style sheets,
JavaFX GUI development, JavaFX application development">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>JavaFX CSS Reference Guide</title>
<style type="text/css">
body {
font-family: Helvetica, Arial, sans-serif;
font-size: 14px;
}
h1 {
font-size: 28px;
color:#385E76
}
h2 {
border-top: 3px dashed #DDD;
margin-top: 30px;
padding-top: 15px;
font-size: 22px;
color:#385E76
}
h3 {
background-color: #EEE;
padding: 3px;
font-size: 18px;
}
h4 {
font-size: 16px;
margin: 18px 0px 10px 0px;
}
ul.contents li {
font-size: 12px;
font-weight:bold;
list-style-type:circle;
margin: 3px 0px 3px 0px;
}
ul.contents li li {
font-weight:normal;
list-style-type:circle;
}
/*ul.contents a {
color:#000
}*/
a {
text-decoration:none;
color:#06C
}
.csspropertytable {
background-color: #CCC;
}
.csspropertytable th {
font-size: 10px;
}
.csspropertytable td {
background-color:#FFF;
font-size: 12px;
}
/*.csspropertytable td:first-child {
color:#06C;
font-weight:bold;
white-space:nowrap;
}*/
.package {
margin: 15px 0px 0px 0px;
padding: 2px;
background-color:#666;
color:#FFF;
font-weight:bold;
border:none
}
.package td {
background-color:#666;
font-size: 14px;
}
td.parents {
font-weight:bold;
color:#C00;
background-color:#DDD;
padding: 4px;
text-align:center;
font-size: 10px;
}
.propertyname {
color:#06C;
font-weight:bold;
white-space:nowrap;
}
td.value {
font-family:"Lucida Console", Monaco, monospace;
font-size: 10px;
}
td.default {
font-family:"Lucida Console", Monaco, monospace;
font-size: 10px;
text-align:center;
white-space:nowrap;
}
td.range {
font-family:"Lucida Console", Monaco, monospace;
font-size: 10px;
text-align:center;
white-space:nowrap;
}
td.implemented {
text-align:center;
white-space:nowrap;
}
.grammar {
font-family:"Lucida Console", Monaco, monospace;
font-size: 14px;
color:#039;
}
p.example {
font-family:"Lucida Console", Monaco, monospace;
font-size: 14px;
/* white-space: pre; */
padding: 0px 0px 0px 40px;
color:#090;
margin: 0px;
}
span.example {
font-family:"Lucida Console", Monaco, monospace;
font-size: 14px;
color:#090;
}
p.subtitle {
font-style: italic;
color:#999;
}
p.styleclass {
font-style: italic;
}
.grammar .typelink , p .typelink , td .typelink{
font-family:"Lucida Console", Monaco, monospace;
font-size: 14px;
color:#039;
}
td.value .typelink {
font-family:"Lucida Console", Monaco, monospace;
font-size: 10px;
color:#039;
}
/* Oracle FX style */
.fx-code-header {
background: #ffffff;
background-image:url(fx_code_header.jpg);
height: 50px;
width: 656px;
}
/* Oracle FX style */
.version {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
padding-top:2px;
color:#265F7F;
line-height:1.2em;
position:relative;
left:425px;
top:10px;
width:200px;
text-align:right;
}
/* Color Table Styles */
table.html4colortable {margin:auto; width:80%; border:none }
table.html4colortable TD {border:none; padding:0}
td .colorsquare { display:block;width:16px;height:16px;border:2px solid black }
</style>
</head>
<body>
<div class="fx-code-header">
<div class="version"><br>
Release: JavaFX 8</div>
</div>
<h1>JavaFX CSS Reference Guide</h1>
<h2>Contents</h2>
<ul class="contents">
<li><a href="#intro">Introduction</a>
<ul>
<li><a href="#introscenegraph">CSS and the JavaFX Scene Graph</a></li>
<li><a href="#introstylesheets">Scene, Parent and SubScene Stylesheets</a></li>
<li><a href="#intronaming">Naming Conventions</a></li>
<li><a href="#intropublicapi">CSS Public API</a></li>
<li><a href="#introinheritance">Inheritance</a></li>
<li><a href="#introatrules">@ Rules</a></li>
<li><a href="#introexamples">Examples</a></li>
<li><a href="#introparserwarnings">Understanding Parser Warnings</a></li>
<li><a href="#introlimitations">Limitations</a></li>
</ul>
</li>
<li><a href="#types">Types</a>
<ul>
<li><a href="#typeinherit">inherit</a></li>
<li><a href="#typeboolean"><boolean></a></li>
<li><a href="#typestring"><string></a></li>
<li><a href="#typenumber"><number> & <integer></a> </li>
<li><a href="#typesize"><size></a></li>
<li><a href="#typelength"><length></a></li>
<li><a href="#typepercentage"><percentage></a></li>
<li><a href="#typeangle"><angle></a></li>
<li><a href="#typeduration"><duration></a></li>
<li><a href="#typepoint"><point></a></li>
<li><a href="#typecolorstop"><color-stop></a></li>
<li><a href="#typeurl"><uri></a></li>
<li><a href="#typeeffect"><effect></a></li>
<li><a href="#typefont"><font></a></li>
<li><a href="#typepaint"><paint></a></li>
<li><a href="#typecolor"><color></a></li>
</ul>
</li>
<li><a href="#stage">Stage</a>
<ul>
<li>javafx.stage
<ul>
<li><a href="#popupwindow">PopupWindow</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#nodes">Nodes</a>
<ul>
<li>javafx.scene
<ul>
<li><a href="#group">Group</a></li>
<li><a href="#node">Node</a></li>
<li><a href="#parent">Parent</a></li>
<li><a href="#scene">Scene</a></li>
</ul>
</li>
</ul>
<ul>
<li>javafx.scene.image
<ul>
<li><a href="#imageview">ImageView</a></li>
</ul>
</li>
</ul>
<ul>
<li>javafx.scene.layout
<ul>
<li><a href="#anchorpane">AnchorPane</a></li>
<li><a href="#border">BorderPane</a></li>
<li><a href="#dialogpane">DialogPane</a></li>
<li><a href="#flowpane">FlowPane</a></li>
<li><a href="#gridpane">GridPane</a></li>
<li><a href="#hbox">HBox</a></li>
<li><a href="#pane">Pane</a></li>
<li><a href="#region">Region</a></li>
<li><a href="#stackpane">StackPane</a></li>
<li><a href="#tilepane">TilePane</a></li>
<li><a href="#vbox">VBox</a></li>
</ul>
</li>
</ul>
<ul>
<li>javafx.scene.media
<ul>
<li><a href="#mediaview">MediaView</a></li>
</ul>
</li>
</ul>
<ul>
<li>javafx.scene.shape
<ul>
<li><a href="#shape">Shape</a></li>
<li><a href="#arc">Arc</a></li>
<li><a href="#circle">Circle</a></li>
<li><a href="#cubiccurve">CubicCurve</a></li>
<li><a href="#ellipse">Ellipse</a></li>
<li><a href="#line">Line</a></li>
<li><a href="#path">Path</a></li>
<li><a href="#polygon">Polygon</a></li>
<li><a href="#quadcurve">QuadCurve</a></li>
<li><a href="#rectangle">Rectangle</a></li>
<li><a href="#svgpath">SVGPath</a></li>
</ul>
</li>
</ul>
<ul>
<li>javafx.scene.text
<ul>
<li><a href="#text">Text</a></li>
</ul>
</li>
</ul>
<ul>
<li>javafx.scene.web
<ul>
<li><a href="#webview">WebView</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#controls">Controls</a>
<ul>
<li>javafx.scene.control
<ul>
<li><a href="#accordion">Accordion</a></li>
<li><a href="#button">Button</a></li>
<li><a href="#buttonbase">ButtonBase</a></li>
<li><a href="#cell">Cell</a></li>
<li><a href="#checkbox">CheckBox</a></li>
<li><a href="#checkmenuitem">CheckMenuItem</a></li>
<li><a href="#choicebox">ChoiceBox</a></li>
<li><a href="#colorpicker">ColorPicker</a></li>
<li><a href="#combobox">ComboBox</a></li>
<li><a href="#contextmenu">ContextMenu</a></li>
<li><a href="#control">Control</a></li>
<li><a href="#datepicker">DatePicker</a></li>
<li><a href="#htmleditor">HTMLEditor</a></li>
<li><a href="#hyperlink">Hyperlink</a></li>
<li><a href="#indexedcell">IndexedCell</a></li>
<li><a href="#label">Label</a></li>
<li><a href="#labeled">Labeled</a></li>
<li><a href="#listcell">ListCell</a></li>
<li><a href="#listview">ListView</a></li>
<li><a href="#menu">Menu</a></li>
<li><a href="#menubar">MenuBar</a></li>
<li><a href="#menubutton">MenuButton</a></li>
<li><a href="#menuitem">MenuItem</a></li>
<li><a href="#menuitembase">MenuItemBase</a></li>
<li><a href="#pagination">Pagination</a></li>
<li><a href="#passwordfield">PasswordField</a></li>
<li><a href="#progressbar">ProgressBar</a></li>
<li><a href="#progressindicator">ProgressIndicator</a></li>
<li><a href="#radiobutton">RadioButton</a></li>
<li><a href="#radiomenuitem">RadioMenuItem</a></li>
<li><a href="#scrollbar">ScrollBar</a></li>
<li><a href="#scrollpane">ScrollPane</a></li>
<li><a href="#separator">Separator</a></li>
<li><a href="#spinner">Spinner</a></li>
<li><a href="#slider">Slider</a></li>
<li><a href="#splitmenubutton">SplitMenuButton</a></li>
<li><a href="#splitpane">SplitPane</a></li>
<li><a href="#tabpane">TabPane</a></li>
<li><a href="#tablecolumnheader">TableColumnHeader</a></li>
<li><a href="#tableview">TableView</a></li>
<li><a href="#text-area">TextArea</a></li>
<li><a href="#textinputcontrol">TextInputControl</a></li>
<li><a href="#textfield">TextField</a></li>
<li><a href="#titledpane">TitledPane</a></li>
<li><a href="#togglebutton">ToggleButton</a></li>
<li><a href="#toolbar">ToolBar</a></li>
<li><a href="#tooltip">Tooltip</a></li>
<li><a href="#treecell">TreeCell</a></li>
<li><a href="#treetablecell">TreeTableCell</a></li>
<li><a href="#treetableview">TreeTableView</a></li>
<li><a href="#treeview">TreeView</a></li>
<li><a href="#webview">WebView</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#charts">Charts</a>
<ul>
<li> javafx.scene.chart
<ul>
<li><a href="#areachart">AreaChart</a> </li>
<li><a href="#axis">Axis</a> </li>
<li><a href="#barchart">BarChart</a> </li>
<li><a href="#bubblechart">BubbleChart</a> </li>
<li><a href="#categoryaxis">CategoryAxis</a> </li>
<li><a href="#chart">Chart</a> </li>
<li><a href="#legend">Legend</a> </li>
<li><a href="#linechart">LineChart</a> </li>
<li><a href="#numberaxis">NumberAxis</a> </li>
<li><a href="#piechart">PieChart</a> </li>
<li><a href="#scatterchart">ScatterChart</a> </li>
<li><a href="#valueaxis">ValueAxis</a> </li>
<li><a href="#xychart">XYChart</a> </li>
</ul>
</li>
</ul>
</li>
<li><a href="#references">References</a></li>
</ul>
<h2><a name="intro" id="intro">Introduction</a></h2>
<p>
Never has styling a Java UI been easier than with JavaFX and Cascading Style Sheets (CSS). Going from one
theme to another, or customizing the look of just one control, can all be done through CSS. To the novice,
this may be unfamiliar territory; but the learning curve is not that great. Give CSS styling a try and the
benefits will soon be apparent. You can also split the design and development workflow, or defer design
until later in the project. Up to the last minute changes, and even post-deployment changes, in the UI's
look can be achieved through JavaFX CSS.
</p>
<p>
The structure of this document is as follows. First, there is a
description of all value types for JavaFX CSS properties.Where
appropriate, this includes a grammar for the syntax of values of that
type. Then, for each scene‑graph node that supports CSS styles, a table is
given that lists the properties that are supported, along with type and
semantic information. The pseudo‑classes for each class are also given.
The description of CSS properties continues for the controls. For each
control, the substructure of that control's skin is given, along with the
style‑class names for the Region objects that implement that substructure.
</p>
<h3><a name="introscenegraph" id="introscenegraph">CSS and the JavaFX Scene Graph</a></h3>
<p>
JavaFX Cascading Style Sheets (CSS) is based on the W3C CSS version 2.1 <a href="#references">[1]</a>
with some additions from current work on version 3 <a href="#references">[2]</a>.
JavaFX CSS also has some extensions to CSS in support of specific JavaFX
features. The goal for JavaFX CSS is to allow web developers already
familiar with CSS for HTML to use CSS to customize and develop themes for
JavaFX controls and scene‑graph objects in a natural way.
</p>
<p>
JavaFX has a rich set of extensions to CSS in support of features such as
color derivation, property lookup, and multiple background colors and
borders for a single node. These features add significant new power for
developers and designers and are described in detail in this document.
</p>
<p>
To the extent possible, JavaFX CSS follows the W3C standards; however, with few exceptions, JavaFX
property names have been prefixed with a vendor extension of "-fx-". Even if these properties seem to be
compatible with standard HTML CSS, JavaFX CSS processing assumes that the property values
make use of JavaFX CSS extensions.
</p>
<p>CSS styles are applied to nodes in the JavaFX scene‑graph in a way
similar to the way CSS styles are applied to elements in the HTML DOM.
Styles are first applied to the parent, then to its children. The code is
written such that only those branches of the scene‑graph that might need
CSS reapplied are visited. A node is styled after it is added to the scene
graph. Styles are reapplied when there is a change to the node's
pseudo‑class state, style‑class, id, inline style, or parent, or stylesheets
are added to or removed from the scene. Note that the Node must be in the
scene‑graph for CSS to be applied. The Node does not have
to be shown, but must have a non‑null value for its sceneProperty. See
<a href="../../../javafx/scene/Node.html#applyCss--">applyCss</a> for more details.</p>
<p>
During a normal scene‑graph pulse, CSS styles are applied before the scene‑graph is
laid out and painted. Styles for events that trigger a pseudo‑class state change,
such as MouseEvent.MOUSE_ENTERED which triggers the "hover" state, are
applied on the next pulse following the event.
</p>
<p>
<a href="http://www.w3.org/TR/css3-selectors/">CSS selectors</a> are used to match styles to scene‑graph
nodes.
The relationship of a Node to a CSS selector is as follows:
<ul>
<li>
Node's <a href="../../../javafx/scene/Node.html#getTypeSelector--">getTypeSelector</a> method returns a
String which is analogous to a CSS <a href="http://www.w3.org/TR/css3-selectors/#type-selectors">Type
Selector</a>.
By default, this method returns the simple name of the class. Note that the simple name of an inner class
or of an anonymous class may not be usable as a type selector. In such a case, this method should be
overridden to return
a meaningful value.
</li>
<li>
Each node in the scene‑graph has a <a href="../../../javafx/scene/Node.html#getStyleClass--">styleClass
property</a>.
Note that a node may have more than one style‑class.
A Node's styleClass is analogous to the class="..." attribute that can
appear on HTML elements. See <a href="http://www.w3.org/TR/css3-selectors/#class-html">Class Selectors</a>.
</li>
<li>
Each node in the scene‑graph has an <strong>id</strong> variable, a
string. This is analogous to the id="..." attribute that can appear HTML
elements. See <a href="http://www.w3.org/TR/css3-selectors/#id-selectors">ID Selectors</a>.
</li>
</ul>
<p>
JavaFX CSS also supports pseudo‑classes, but does not implement the full range of pseudo‑classes as
specified in <a href="http://www.w3.org/TR/css3-selectors/#pseudo-classes">Pseudo‑classes</a>. The pseudo‑classes
supported by each Node type are given in the tables within this reference. Note that JavaFX does not currently
support structural pseudo‑classes.
</p>
<p>
Each node honors a set of properties that depends on the node's JavaFX
class (as distinct from its styleClass). The properties honored by each
node class are shown in detail in tables later in this document. The
property value that is actually applied depends on the precedence of the
origin of the rule, as described above, as well as the specificity of the
rule's selector as described in CSS 2 <a href="cssref.html#references">[1]</a>
. Ultimately, a property value string is converted into a JavaFX value of
the appropriate type and is then assigned to an instance variable of the
JavaFX object.
</p>
<h3><a name="introstylesheets" id="introstylesheets">Scene, Parent and SubScene Stylesheets</a></h3>
<p>
CSS styles can come from style sheets or inline styles. Style sheets are
loaded from the URLs specified in the
<a href="../../../javafx/scene/Scene.html#getStylesheets--">getStylesheets</a>
property of the Scene object. If the scene‑graph contains a Control, a
default user agent style sheet is loaded. Inline styles are specified via
the Node <span style="font-weight: bold;">setStyle</span> API. Inline
styles are analogous to the style="..." attribute of an HTML element.
Styles loaded from a Scene's style sheets take precedence over selectors from
the user agent style sheet. Inline styles take precedence over
styles originating elsewhere. The precedence order of style selectors can be
modified using "!important" in a style declaration.
</p>
<p>
Beginning with JavaFX 2.1, the Parent class has a
<a href="../../../javafx/scene/Parent.html#getStylesheets--">getStylesheets</a> property,
allowing style sheets to be set on a container. This allows for one branch
of of the scene‑graph to have a distinct set of styles. Any instance of
Parent can have style sheets. A child will take its styles from its own
inline styles, the style sheets of all its ancestors, and any style sheets
from the Scene.
</p>
<p>
Beginning with JavaFX 8u20, the Scene class has a
<a href="../../../javafx/scene/Scene.html#getUserAgentStylesheet--">getUserAgentStylesheet</a> property,
allowing a user‑style sheet to be set on a Scene. This allows a Scene
to have a set of user‑agent styles distinct from the platform default. When a user‑agent
stylesheet is set on a Scene, the user‑agent styles are used instead of the styles from the
platform default user‑agent stylesheet.
</p>
<p>
Beginning with JavaFX 8u20, the SubScene class has a
<a href="../../../javafx/scene/SubScene.html#getUserAgentStylesheet--">getUserAgentStylesheet</a> property,
allowing a user‑style sheet to be set on a SubScene. This allows a SubScene
of the scene‑graph to have set of user‑agent styles distinct from the platform default
or from the Scene in which the SubScene is contained. When a user‑agent
stylesheet is set on a SubScene, the user‑agent styles are used instead of the styles from the
platform default user‑agent stylesheet or any user‑agent stylesheet set on the Scene.
</p>
<p>It is important to note that styles from a stylesheet added to a Scene or Parent, do not affect
a SubScene which is a child or descendent of the Scene or Parent. Unless a user‑agent has
been set on the SubScene, the SubScene will get styles
from the a Scene's user‑agent stylesheet or the platform user‑agent stylesheet.</p>
The implementation allows designers to style an application by using style
sheets to override property values set from code. For example, a call to <code>rectangle.setFill(Color.YELLOW)</code>
can be overridden by an inline‑style or a style from an author stylesheet. This has implications for
the cascade; particularly, when does a style from a style sheet override a
value set from code? The JavaFX CSS implementation applies the following
order of precedence: <cite>a style from a user agent style sheet has lower
priority than a value set from code, which has lower priority than a Scene
or Parent style sheet. Inline styles have highest precedence. Style sheets
from a Parent instance are considered to be more specific than those styles
from Scene style sheets.</cite>
<h3><a name="intronaming" id="introsnaming">Naming Conventions</a></h3>
<p>Naming conventions have been established for deriving CSS style‑class
names from JavaFX class names, and for deriving CSS property names from
JavaFX variable names. Note that this is only a naming convention; there
is no automatic name conversion. Most JavaFX names use "camel case," that
is, mixed case names formed from compound words, where the initial letter
of each sub-word is capitalized. Most CSS names in the HTML world are all
lower case, with compound words separated by hyphens. The convention is
therefore to take JavaFX class names and form their corresponding CSS
style‑class name by separating the compound words with hyphens and
convering the letters to all lower case. For example, the JavaFX
ToggleButton class would have a style‑class of "toggle-button". The
convention for mapping JavaFX variable names to CSS property names is
similar, with the addition of the "-fx-" prefix. For example, the
blendMode variable would have a corresponding CSS property name of
"-fx-blend-mode". </p>
<h3><a name="intropublicapi" id="intropublicapi">CSS Public API</a></h3>
Beginning with JavaFX 8.0, public API is available for developers to create styleable properties and manage
pseudo-class state. Refer to <a href="../../../javafx/css/package-summary.html">javafx.css</a> for details.
<h3><a name="introinheritance" id="introinheritance">Inheritance</a></h3>
<p>CSS also provides for certain properties to be inherited by default, or
to be inherited if the property value is 'inherit'. If a value is
inherited, it is inherited from the computed value of the element's parent
in the document tree. In JavaFX, inheritance is similar, except that
instead of elements in the document tree, inheritance occurs from parent
nodes in the scene‑graph. </p>
<p>The following properties inherit by default. Any property can be made to
inherit by giving it the value <a href="#typeinherit" class="typelink">"inherit"</a>.</p>
<table summary="property table" style="width: 100%;" border="1">
<caption><br>
</caption> <colgroup><col> <col> <col> <col> </colgroup>
<tbody>
<tr>
<th>Class</th>
<th>Property</th>
<th>CSS Property</th>
<th>Initial Value</th>
</tr>
<tr>
<td>javafx.scene.Node</td>
<td>cursor</td>
<td>-fx-cursor</td>
<td>javafx.scene.Cursor.DEFAULT</td>
</tr>
<tr>
<td>javafx.scene.text.Text</td>
<td>textAlignment</td>
<td>-fx-text-alignment</td>
<td>javafx.scene.text.TextAlignment.LEFT</td>
</tr>
<tr>
<td>javafx.scene.text.Font</td>
<td>font</td>
<td>-fx-font, -fx-font-family, -fx-font-size, -fx-font-weight, -fx-font-style</td>
<td>Font.DEFAULT (12px system)</td>
</tr>
</tbody>
</table>
<p>Within the hierarchy of JavaFX classes (for example, Rectangle is a
subclass of Shape, which in turn is a subclass of Node), the CSS
properties of an ancestor are also CSS properties of the descendant. This
means that a subclass will respond to the same set of properties as its
ancestor classes, and to additional properties it defines itself. So, a
Shape supports all the properties of Node plus several more, and Rectangle
supports all the properties of Shape plus a couple more. However, because
using a JavaFX class name as a type selector is an exact match, providing
style declarations for a Shape will not cause a Rectangle to use those
values (unless the .css value for the Rectangle's property is "inherit").</p>
<p>For font inheritance, the CSS engine looks <span style="font-style:italic;">only</span> for the styles in the table above. When
looking for a font to inherit, the search
terminates at any node that has a Font property that was set by the user. The user-set font is
inherited provided there is not an author or an inline-style that applies specifically to that node.
In this case, the inherited font is created from the user-set font and any parts of the applicable
author or in-line style.
<h3><a name="introatrules" id="introatrules">@ Rules</a></h3>
<p>
Beginning with JavaFX 8u20, the CSS
<a href="http://www.w3.org/TR/CSS21/cascade.html#at-import">@import</a> is also partially supported.
Only unconditional import is supported. In other words, the media‑type qualifier is not supported.
Also, the JavaFX CSS parser is non-compliant with regard to where an @import may appear within a stylesheet
(see <a href="http://www.w3.org/TR/CSS21/syndata.html#at-rules">At‑rules</a>).
Users are cautioned that this will be fixed in a future release. Adherence to the W3C standard is strongly advised.
</p>
<p>Since JavaFX 8, the implementation partially supports the CSS3 syntax to load a font from a URL using the
<a href="http://www.w3.org/TR/css3-fonts/#the-font-face-rule">@font‑face</a> rule:</p>
<textarea rows="8" cols="132">
@font-face {
font-family: 'sample';
font-style: normal;
font-weight: normal;
src: local('sample'), url('http://font.samples/resources/sample.ttf';) format('truetype');
}
</textarea>
<p>This allows public resources for fonts to be used in a JavaFX application. For example, assume the URL
"http://font.samples/web?family=samples" returns the @font‑face rule given above. Then the
following code shows how the sample font could be used in a JavaFX application.</p>
<textarea rows="20" cols="132">
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
public class HelloFontFace extends Application {
@Override public void start(Stage primaryStage) {
Label label = new Label("Hello @FontFace");
label.setStyle("-fx-font-family: sample; -fx-font-size: 80;");
Scene scene = new Scene(label);
scene.getStylesheets().add("http://font.samples/web?family=samples");
primaryStage.setTitle("Hello @FontFace");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) { launch(args); }
}
</textarea>
<p>Or, the URL could be imported into a stylesheet with the @import rule.</p>
<p>Although the parser will parse the syntax, all @font‑face descriptors are ignored except for
the <code>src</code> descriptor. The <code>src</code> descriptor is expected to be a
<a href="#typeurl" class="typelink"><url></a>. The <code>format</code> hint is ignored.</p>
<h3><a name="introexamples" id="introexamples">Examples</a></h3>
<p>Consider the following simple JavaFX application: </p>
<p class="example">Scene scene = new Scene(new Group()); <br>
scene.getStylesheets().add(“test.css”); <br>
Rectangle rect = new Rectangle(100,100); <br>
rect.setLayoutX(50); <br>
rect.setLayoutY(50); <br>
rect.getStyleClass().add("my-rect"); <br>
((Group)scene.getRoot()).getChildren().add(rect); </p>
<p>Without any styles, this will display a plain black rectangle. If
test.css contains the following: </p>
<p class="example">.my-rect { -fx-fill: red; }</p>
<p>the rectangle will be red instead of black: </p>
<p><img src="cssexample1.png" alt="A rectangle with red fill"></p>
<p>If test.css contains the following: </p>
<p class="example">.my-rect {<br>
-fx-fill: yellow;<br>
-fx-stroke: green;<br>
-fx-stroke-width: 5;<br>
-fx-stroke-dash-array: 12 2 4 2;<br>
-fx-stroke-dash-offset: 6;<br>
-fx-stroke-line-cap: butt;<br>
}<br>
</p>
<p>the result will be a yellow rectangle with a nicely dashed green border:
</p>
<p><img src="cssexample2.png" alt="A rectangle with yellow fill and a green, dashed border"></p>
<h3><a name="introparserwarnings" id="introparserwarnings">Understanding
Parser Warnings</a></h3>
<p>When the JavaFX CSS parser encounters a syntax error, a warning message
is emitted which conveys as much information as is available to help
resolve the error. For example </p>
<p class="example"> WARNING: com.sun.javafx.css.parser.CSSParser declaration
Expected '<percent>' while parsing '-fx-background-color' at ?[1,49]
</p>
<p>The cryptic '<span class="p example">?[1,49]</span>' pertains to the
location of the error. The format of the location string is </p>
<p class="grammar"><url>[line, position]</p>
<p>If the error is found while parsing a file, the file URL will be given.
If the error is from an inline style (as in the example above), the URL is
given as a question mark. The line and position give an offset into the
file or string where the token begins. <em>Please note that the line and
position may not be accurate in releases prior to JavaFX 2.2.</em><br>
</p>
<p>Applications needing to detect errors from the parser can add a listener
to the errors property of com.sun.javafx.css.StyleManager. This is not
public API and is subject to change. <br>
</p>
<h3><a name="introlimitations" id="introlimitations">Limitations</a></h3>
<ol>
<li> While the JavaFX CSS parser will parse valid CSS syntax, it is not a
fully compliant CSS parser. One should not expect the parser to handle
syntax not specified in this document.</li>
<li>With the exception of @font‑face and @import, @-keyword statements are ignored.</li>
<li>The <media-query-list> of the @import statement is not parsed.</li>
<li>The structural pseudo‑classes are not supported. </li>
<li>The ":active" and ":focus" dynamic pseudo‑classes are not supported.
However, <a href="#node">Nodes</a> do support the ":pressed" and
":focused" pseudo‑classes, which are similar. </li>
<li>The ":link" and ":visited" pseudo‑classes are not supported in general.
However, <a href="#hyperlink">Hyperlink</a> objects can be styled, and
they support the ":visited" pseudo‑class. </li>
<li>JavaFX CSS does not support comma-separated series of font family names
in the -fx-font-family property. The optional line height parameter when
specifying fonts is not supported. There is no equivalent for the
font-variant property.</li>
<li>JavaFX CSS uses the HSB color model instead of the HSL color model. </li>
<li>If a property of a node is initialized by calling the set method of the
property, the CSS implementation will see this as a user set value and the
value will not be overwritten by a style from a user agent style
sheet.</li>
<li>When parsing a <a href="http://www.w3.org/TR/CSS2/syndata.html#uri">URI</a>,
the parser doesn't handle URI escapes nor \<hex-digit>[1,6] code points.</li>
</ol>
<h2><a name="types" id="types">Types</a></h2>
<h3><a name="typeinherit" id="typeinherit">inherit</a></h3>
<p>Each property has a type, which determines what kind of value and the
syntax for specifying those values. In addition, each property may have a
specified value of 'inherit', which means that, for a given node, the
property takes the same computed value as the property for the node's
parent. The 'inherit' value can be used on properties that are not
normally inherited.
</p>
<p>If the 'inherit' value is set on the root element, the property is
assigned its initial value.</p>
<h3><a name="typeboolean" id="typeboolean"><boolean></a></h3>
<p>Boolean values can either have the string value of "true" or "false", the
values are case insensitive as all CSS is case insensitive.</p>
<h3><a name="typestring" id="typestring"><string></a></h3>
<p>Strings can either be written with double quotes or with single quotes.
Double quotes cannot occur inside double quotes, unless escaped (e.g., as
'\"' or as '\22'). Analogously for single quotes (e.g., "\'" or "\27").</p>
<p class="example">"this is a 'string'"<br>
"this is a \"string\""<br>
'this is a "string"'<br>
'this is a \'string\''</p>
<p>A string cannot directly contain a newline. To include a newline in a
string, use an escape representing the line feed character in ISO-10646
(U+000A), such as "\A" or "\00000a". This character represents the generic
notion of "newline" in CSS. See the 'content' property for an example.</p>
<h3><a name="typenumber" id="typenumber"><number> &
<integer></a></h3>
<p>Some value types may have integer values (denoted by <integer>) or
real number values (denoted by <number>). Real numbers and integers
are specified in decimal notation only. An <integer> consists of one
or more digits "0" to "9". A <number> can either be an
<integer>, or it can be zero or more digits followed by a dot (.)
followed by one or more digits. Both integers and real numbers may be
preceded by a "-" or "+" to indicate the sign. -0 is equivalent to 0 and
is not a negative number.</p>
<p class="grammar">[+|-]? [[0-9]+|[0-9]*"."[0-9]+]</p>
<p>Note that many properties that allow an integer or real number as a value
actually restrict the value to some range, often to a non-negative value.</p>
<h3><a name="typesize" id="typesize"><size></a></h3>
<p>A size is a <a href="#typenumber" class="typeref"><number></a>
with units of <a href="#typelength" class="typeref"><length></a> or
<a href="#typepercentage" class="typeref"><percentage></a>. If units
are not specified then specified the 'px' is assumed.</p>
<h4><a name="typelength" id="typelength"><length></a></h4>
<p class="grammar"><a href="#typenumber"><number></a>[ px | mm | cm |
in | pt | pc | em | ex ]?</p>
<p>No whitespace is allowed between the number and units if provided. Some
units are relative and others absolute. </p>
<p><strong>Relative</strong></p>
<ul>
<li><strong>px</strong>: pixels, relative to the viewing device</li>
<li><strong>em</strong>: the 'font-size' of the relevant font</li>
<li><strong>ex</strong>: the 'x-height' of the relevant font</li>
</ul>
<p><strong>Absolute</strong></p>
<ul>
<li><strong>in</strong>: inches — 1 inch is equal to 2.54
centimeters.</li>
<li><strong>cm</strong>: centimeters</li>
<li><strong>mm</strong>: millimeters</li>
<li><strong>pt</strong>: points — the points used by CSS 2.1 are
equal to 1/72nd of an inch.</li>
<li><strong>pc</strong>: picas — 1 pica is equal to 12 points.</li>
</ul>
<h4><a name="typepercentage" id="typepercentage"><percentage></a></h4>
<p>These are a percentage of some length, typically to the width or height
of a node.</p>
<p class="grammar"><a href="#typenumber"><number></a>[ % ]</p>
<h3><a name="typeangle" id="typeangle"><angle></a></h3>
<p>An angle is a <a href="#typenumber" class="typeref"><number></a>
with one of the following units.</p>
<p> </p>
<p class="grammar"><a href="#typenumber"><number></a>[ deg | rad |
grad | turn ]</p>
<ul>
<li><strong>deg</strong>: angle in degrees — all other angle units are
converted to degrees.</li>
<li><strong>rad</strong>: angle in radians</li>
<li><strong>grad</strong>: angle in gradians</li>
<li><strong>turn</strong>: angle in turns</li>
</ul>
<h3><a name="typeduration" id="typeduration"><duration></a></h3>
<p>A duration is a <a href="#typenumber" class="typeref"><number></a>
with second or millisecond units, or the value <span class="grammar">indefinite</span>.</p>
<p> </p>
<p class="grammar">[<a href="#typenumber"><number></a>[ s | ms ]] | indefinite</p>
<ul>
<li><strong>s</strong>: duration in seconds</li>
<li><strong>ms</strong>: duration in milliseconds. One second is 1000 milliseconds.</li>
<li><strong>indefinite</strong>: See <a href="../../util/Duration.html#INDEFINITE" class="typelink">Duration.INDEFINITE</a></li>
</ul>
<p>See also <a href="http://www.w3.org/TR/css3-values/#time" class="typelink">W3C time units</a>.</p>
<h3><a name="typepoint" id="typepoint"><point></a></h3>
<p>A point is an {x,y} coordinate.</p>
<p class="grammar">[ [ <length> <length> ] | [
<percentage> | <percentage> ] ]</p>
<h3><a name="typecolorstop" id="typecolorstop"><color-stop></a></h3>
<p>Stops are per <a href="http://dev.w3.org/csswg/css3-images/#color-stop-syntax."
class="typelink">W3C
color-stop syntax</a>.</p>
<p class="grammar">[ <a href="#typecolor" class="typeref"><color></a>
[ <a href="#typepercentage" class="typeref"><percentage></a> | <a
href="#typelength"
class="typeref"><length></a>]?
]</p>
<p>In a series of <color-stop>, stop distance values must all be
<percentage> or <length>. Furthermore, if <length>
values are used, then the distance value for first and last stop in the
series must be specified. This restriction may be removed in a future
release.</p>
<p>"<span style="color: #009900; ">red, white 70%, blue</span>" is valid since the
distance for red and blue is assumed to be 0% and 100%, respectively.</p>
<p>"<span style="color: #009900; ">red 10, white, blue 90</span>" is valid. Because
distance for red and blue is 10 and 90, respectively, the distance for
white can be calculated.</p>
<p>"<span style="color: #009900; ">red, white 70, blue</span>" is <span style="font-style:italic;">not</span> valid
since distance units do not agree.</p>
<p>"<span style="color: #009900; ">red, white, blue</span>" is valid. The stops are
distributed evenly between 0% and 100%.</p>
<h3><a name="typeurl" id="typeurl"><uri></a></h3>
<p class="grammar">url ( [\"\']? <address> [\"\']? )</p>
<p><span class="grammar"><address></span> is a hierarchical URI of the form [scheme:][//authority][path] <a href="#references">(see [2])</a>.
For example:</p>
<p class="example">
url(http://example.com/images/Duke.png)<br>
url(/com/example/javafx/app/images/Duke.png)<br>
</p>
<p>If the <span class="grammar"><address></span> does not have a [scheme:] component, the <span class="grammar"><address></span>
is considered to be the [path] component only.
A leading '/' character indicates that the [path] is relative to the
root of the classpath. If the the style appears in a stylesheet and
has no leading '/' character, the path is relative to the base URI of
the stylesheet. If the style appears in an inline style, the path is
relative to the root of the classpath (regardless of whether or not
there is a leading '/').
</p>
<table class="csspropertytable" cellspacing="3" cellpadding="4">
<caption>Examples of Resolving URLs in Stylesheets</caption>
<tr>
<th>Stylesheet URL</th><th>URL in Style</th><th>Resolves to</th>
</tr>
<tr>
<td>file:///some/path/build/classes/com/mycompany/myapp/mystyles.css</td>
<td>url(images/Duke.png)</td>
<td>file:///some/path/build/classes/com/mycompany/myapp/images/Duke.png</td>
</tr>
<tr>
<td>file:///some/path/build/classes/com/mycompany/myapp/mystyles.css</td>
<td>url(../images/Duke.png)</td>
<td>file:///some/path/build/classes/com/mycompany/images/Duke.png</td>
</tr>
<tr>
<td>jar:file:/some/path/build/myapp.jar!/com/mycompany/myapp/mystyles.css</td>
<td>url(images/Duke.png)</td>
<td>jar:file:/some/path/build/myapp.jar!/com/mycompany/myapp/images/Duke.png</td>
</tr>
</table>
<p></p>
<table class="csspropertytable" cellspacing="3" cellpadding="4">
<caption>Examples of Resolving URLs in Inline Styles</caption>
<tr>
<th>Classpath</th><th>URL in Style</th><th>Resolved URL</th>
</tr>
<tr>
<td>file:///some/path/build/classes</td>
<td>url(/com/mycompany/resources/images/Duke.png)</td>
<td>file:///some/path/build/classes/com/mycompany/resources/images/Duke.png</td>
</tr>
<tr>
<td>file:///some/path/build/myapp.jar</td>
<td>url(/com/mycompany/resources/images/Duke.png)</td>
<td>jar:file:/some/path/build/myapp.jar!/com/mycompany/resources/images/Duke.png</td>
</tr>
</table>
<p>Note that for inline styles, leading dot-segments (e.g. '..' or '.') do resolve since the path is always
anchored at the root of the classpath.</p>
<p>This snippet of code creates a scene filled with the "paste" image from HTMLEditor which is found in jfxrt.jar.</p>
<textarea rows="9" cols="132">
@Override public void start(Stage stage) {
StackPane root = new StackPane();
root.setStyle("-fx-background-image: url(/com/sun/javafx/scene/control/skin/modena/HTMLEditor-Paste.png);");
Scene scene = new Scene(root, 300, 250);
stage.setScene(scene);
stage.show();
}
</textarea>
<p>The same style would work equally as well from a stylesheet.</p>
<h3><a name="typeeffect" id="typeeffect"><effect></a></h3>
<p>JavaFX CSS currently supports the DropShadow and InnerShadow effects from
the JavaFX platform. See the class documentation in javafx.scene.effect
for further details about the semantics of the various effect parameters.</p>
<h4>Drop Shadow</h4>
<p>A high-level effect that renders a shadow of the given content behind the
content.</p>
<p><span class="grammar">dropshadow( <blur-type> , <a href="#typecolor"
class="typelink"><color></a>
, <a href="#typenumber" class="typelink"><number></a> , <a href="#typenumber"
class="typelink"><number></a>
, <a href="#typenumber" class="typelink"><number></a> , <a href="#typenumber"
class="typelink"><number></a>
)</span></p>
<p style="margin-left: 40px;"><span class="grammar"><blur-type> = [
gaussian | one-pass-box | three-pass-box | two-pass-box ]<br>
<a href="#typecolor" class="typelink"><color></a></span> The
shadow Color.<br>
<span class="grammar"><a href="#typenumber" class="typelink"><number></a></span>
The radius of the shadow blur kernel. In the range [0.0 ... 127.0],
typical value 10.<br>
<span class="grammar"><a href="#typenumber" class="typelink"><number></a></span>
The spread of the shadow. The spread is the portion of the radius where
the contribution of the source material will be 100%. The remaining
portion of the radius will have a contribution controlled by the blur
kernel. A spread of 0.0 will result in a distribution of the shadow
determined entirely by the blur algorithm. A spread of 1.0 will result in
a solid growth outward of the source material opacity to the limit of the
radius with a very sharp cutoff to transparency at the radius. Values
should be in the range [0.0 ... 1.0].<br>
<span class="grammar"><a href="#typenumber" class="typelink"><number></a></span>
The shadow offset in the x direction, in pixels. <br>
<span class="grammar"><a href="#typenumber" class="typelink"><number></a></span>
The shadow offset in the y direction, in pixels. </p>
<h4>Inner Shadow</h4>
<p>A high-level effect that renders a shadow inside the edges of the given
content.</p>
<p><span class="grammar">innershadow( <blur-type> , <a href="#typecolor"
class="typelink"><color></a>
, <a href="#typenumber" class="typelink"><number></a> , <a href="#typenumber"
class="typelink"><number></a>
, <a href="#typenumber" class="typelink"><number></a> , <a href="#typenumber"
class="typelink"><number></a>
)</span></p>
<p style="margin-left: 40px;"><span class="grammar"><blur-type> = [
gaussian | one-pass-box | three-pass-box | two-pass-box ]<br>
</span><span class="grammar"><a href="#typecolor" class="typelink"><color></a></span>
The shadow Color.<br>
<span class="grammar"><a href="#typenumber" class="typelink"><number></a></span>
The radius of the shadow blur kernel. In the range [0.0 ... 127.0],
typical value 10.<br>
<span class="grammar"><a href="#typenumber" class="typelink"><number></a></span>
The choke of the shadow. The choke is the portion of the radius where the
contribution of the source material will be 100%. The remaining portion of
the radius will have a contribution controlled by the blur kernel. A choke
of 0.0 will result in a distribution of the shadow determined entirely by
the blur algorithm. A choke of 1.0 will result in a solid growth inward of
the shadow from the edges to the limit of the radius with a very sharp
cutoff to transparency inside the radius. Values should be in the range
[0.0 ... 1.0].<br>
<span class="grammar"><a href="#typenumber" class="typelink"><number></a></span>
The shadow offset in the x direction, in pixels. <br>
<span class="grammar"><a href="#typenumber" class="typelink"><number></a></span>
The shadow offset in the y direction, in pixels. </p>
<h3><a name="typefont" id="typefont"><font></a></h3>
<p>JavaFX CSS supports the ability to specify fonts using separate family,
size, style, and weight properties, as well as the ability to specify a
font using a single shorthand property. There are four value types related
to fonts plus a shorthand property that encompasses all four properties.
The font-related types are as follows. </p>
<p><span class="grammar"><font-family></span>The string name of the