Contribution Overview
CSSBuilder is based on Swing Clarity, a framework created by Ben Galbraith. It makes styling a Swing application with CSS a breeze.
Team Members
Andres Almiray [aalmiray at users dot sourceforge dot net]
Download
Installing
Drop cssbuilder-1.0.0 into $GROOVY_HOME/lib along with its dependencies
Maven
Gradle
Pre-requisites
Groovy 2.1.0 is the required minimum version to run CSSBuilder 1.0.0
Documentation
CSSBuilder does not add new nodes as opposed to other popular builders, however it enhances every node with a new attribute: cssClass. Use this attribute to define (at least one) CSS class to be applied to that particular component. Additionally you can specify a name: property that will be used as a CSS id. This builder injects the following methods to the java.awt.Container class
$(String name) - performs a component lookup by name, returns a JComponent
$(String... names) - performs component lookup by names, returns a JComponent[]
$$(String selector) - performs component lookup by CSS selector, returns a JComponent[]
This is the list of currently supported CSS properties and some non-standard Swing related properties
Property | Values | Maps to | Applied to |
|---|---|---|---|
font-family |
| setFont() | JComponent |
font-size | xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger | setFont() | JComponent |
font-weight | normal, bold | setFont() | JComponent |
font-style | normal, italic | setFont() | JComponent |
color | a CSS2 color or a hex color starting with # | setForeground() | JComponent |
background-color | a CSS2 color or a hex color starting with # | setBackground() | JComponent |
width | an integer value | setSize() | JComponent |
height | an integer value | setSize() | JComponent |
min-width | an integer value | setMinimumSize() | JComponent |
min-height | an integer value | setMinimumSize() | JComponent |
max-width | an integer value | setMaximumSize() | JComponent |
max-height | an integer value | setMaximumSize() | JComponent |
pref-width | an integer value | setPreferredSize() | JComponent |
pref-height | an integer value | setPreferredSize() | JComponent |
padding | a set of 1, 2, 3 or 4 integer values | setBorder() | JComponent |
padding-top | an integer value | setBorder() | JComponent |
padding-bottom | an integer value | setBorder() | JComponent |
padding-left | an integer value | setBorder() | JComponent |
padding-right | an integer value | setBorder() | JComponent |
border-color | a CSS2 color or a hex color starting with # | setBorder() | JComponent |
border-width | a set of 1, 2, 3 or 4 integer values | setBorder() | JComponent |
border-top-width | an integer value | setBorder() | JComponent |
border-left-width | an integer value | setBorder() | JComponent |
border-bottom-width | an integer value | setBorder() | JComponent |
border-right-width | an integer value | setBorder() | JComponent |
swing-row-height | an integer value | setRowHeight() | JTable |
swing-client-property | a Groovy map literal surrounded with quotes | putClientProperty() | JComponent |
swing-halign | left, right, or center | setHorizontalAlignment() | JLabel |
swing-valign | top, bottom or middle | setVerticalAlignment() | JLabel |
swing-cell-height | an integer value | setFixedCellHeight() | JList |
swing-cell-width | an integer value | setFixedCellWidth() | JList |
swing-row-margin | an integer value | setRowMargin() | JTable |
swing-grid-color | a CSS2 color or a hex color starting with # | setGridColor() | JTable |
swing-selection-color | a CSS2 color or a hex color starting with # | setSelectionForeGround() | JTable |
swing-selection-background-color | a CSS2 color or a hex color starting with # | setSelectionBackground() | JTable |
swing-row-selection-allowed | boolean | setRowSelectionAllowed() | JTable |
swing-column-selection-allowed | boolean | setColumnSelectionAllowed() | JTable |
swing-auto-resize-mode | off, next_column, last_column, all_columns, subsequent_columns | setAutoResizeMode() | JTable |
swing-show-grid | boolean | setShowGrid() | JTable |
swing-show-vertical-lines | boolean | setShowVerticalLines() | JTable |
swing-cell-selection-enabled | boolean | setCellSelectionEnabled() | JTable |
swing-show-horizontal-lines | boolean | setShowHorizontalLines() | JTable |
swing-fills-viewport-height | boolean | setFillsViewportHeight() | JTable |
swing-selection-mode | single, single_interval, multiple_interval | setSelectionMode() | JTable |
swing-border-painted | boolean | setBorderPainted | JToolBar |
swing-floatable | boolean | setFloatable() | JToolBar |
swing-margin | an integer value | setMargin() | JToolbBar |
swing-orientation | horizontal, vertical | setOrientation() | JToolBar |
swing-rollover | boolean | setRollover() | JToolBar |
swing-columns | an integer value | setColumns() | JTextField |
swing-rows | an integer value | setRows() | JTextArea |
swing-line-wrap | boolean | setLineWrap() | JTextArea |
swing-tab-size | an integer value | setTabSize() | JTextArea |
swing-tab-placement | top, left, bottom, right | setTabPlacement() | JTabbedPane |
swing-tab-layout-policy | wrap, scroll | setTabLayoutPolicy() | JTabbedPane |
swing-wrap-style-word | boolean | setWrapStyleWord() | JTextArea |
swing-caret-color | a CSS2 color or a hex color starting with # | setCaretColor() | JTextComponent |
swing-disabled-text-color | a CSS2 color or a hex color starting with # | setDisabledTextColor() | JTextComponent |
swing-selected-text-color | a CSS2 color or a hex color starting with # | setSelectedTextColor() | JTextComponent |
swing-editable | boolean | setEditable() | JTextComponent |
swing-horizontal-scrollbar-policy | as_needed, never, always | setHorizontalScrollBarPolicy() | JScrollPane |
swing-vertical-scrollbar-policy | as_needed, never, always | setVerticalScrollBarPolicy() | JScrollPane |
swing-viewport-border-color | a CSS2 color or a hex color starting with # | setViewportBorder() | JScrollPane |
swing-viewport-border-width | an integer value | setViewportBorder() | JScrollPane |
swing-viewport-border-top-width | an integer value | setViewportBorder() | JScrollPane |
swing-viewport-border-left-width | an integer value | setViewportBorder() | JScrollPane |
swing-viewport-border-bottom-width | an integer value | setViewportBorder() | JScrollPane |
swing-viewport-border-right-width | an integer value | setViewportBorder() | JScrollPane |
swing-horizontal-text-position | left, center, right, leading, trailing | setHorizontalTextPosition() | JLabel |
swing-vertical-text-position | top, middle, bottom | setVerticalTextPosition() | JLabel |
swing-icon-text-gap | an integer value | setIconTextGap() | JLabel |
swing-resizable | boolean | setResizable() | JFrame |
swing-indeterminate | boolean | setIndeterminate() | JProgressBar |
swing-minimum | an integer value | setMinimum() | JProgressBar |
swing-maximum | an integer value | setMaximum() | JProgressBar |
swing-inverted | boolean | setInverted() | JSlider |
swing-paint-labels | boolean | setPaintLabels() | JSlider |
swing-paint-ticks | boolean | setPaintTicks() | JSlider |
swing-paint-tracks | boolean | setPaintTracks() | JSlider |
swing-snap-to-ticks | boolean | setSnapToTicks() | JSlider |
You can use the following selectors:
- * (star) will match every component
- <classname> will match all components of that classname, example
jbutton - #<name> matches a component by its
name:attribute - .<class> matches a component by its
cssClass:attribute
Here is a sample demonstration of its usage, the following application relies solely on CSSBuilder to change its looks

stylesheet
view script
This style sheet was applied using
All CSSDecorate.decorate() variants will read a stylesheet from a file, however if you would like to set an style using a String then make sure to call CSSDecorator.applyStyle() instead.
Starting with version 0.3 you'll be able to use Groovy expressions as values of CSS rules. You may add variables to a global CSSBindings object. CSSBindings's variables are observable. The following example demonstrates these new features
Developers
Andres Almiray
Source Control
Building
CssBuilder uses Gradle as its build tool.
Contributing
Please contact the Griffon team members by e-mail.



