1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 2 <html> 3 <head> 4 <!-- 5 Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 6 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 8 This code is free software; you can redistribute it and/or modify it 9 under the terms of the GNU General Public License version 2 only, as 10 published by the Free Software Foundation. Oracle designates this 11 particular file as subject to the "Classpath" exception as provided 12 by Oracle in the LICENSE file that accompanied this code. 13 14 This code is distributed in the hope that it will be useful, but WITHOUT 15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 version 2 for more details (a copy is included in the LICENSE file that 18 accompanied this code). 19 20 You should have received a copy of the GNU General Public License version 21 2 along with this work; if not, write to the Free Software Foundation, 22 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23 24 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 25 or visit www.oracle.com if you need additional information or have any 26 questions. 27 28 29 --> 30 <title></title> 31 </head> 32 <body bgcolor="white"> 33 <p> 34 Synth is a skinnable look and feel in which all painting is 35 delegated. Synth does not provide a default look. In 36 order to use Synth you need to specify a 37 <a href="doc-files/synthFileFormat.html">file</a>, or 38 provide a {@link 39 javax.swing.plaf.synth.SynthStyleFactory}. Both 40 configuration options require an 41 understanding of the synth architecture, which is described 42 below, as well as an understanding of Swing's architecture. 43 </p> 44 <p> 45 Unless otherwise specified null is not a legal value to any of 46 the methods defined in the synth package and if passed in will 47 result in a <code>NullPointerException</code>. 48 49 50 <h2>Synth</h2> 51 <p> 52 Each {@link javax.swing.plaf.ComponentUI} implementation in Synth associates 53 itself with one {@link 54 javax.swing.plaf.synth.SynthStyle} per {@link 55 javax.swing.plaf.synth.Region}, most 56 <code>Components</code> only have one <code>Region</code> and 57 therefor only one <code>SynthStyle</code>. 58 <code>SynthStyle</code> 59 is used to access all style related properties: fonts, colors 60 and other <code>Component</code> properties. In addition 61 <code>SynthStyle</code>s are used to obtain 62 {@link javax.swing.plaf.synth.SynthPainter}s for painting the background, border, 63 focus and other portions of a <code>Component</code>. The <code>ComponentUI</code>s obtain 64 <code>SynthStyle</code>s from a 65 {@link javax.swing.plaf.synth.SynthStyleFactory}. 66 A <code>SynthStyleFactory</code> 67 can be provided directly by way of 68 {@link javax.swing.plaf.synth.SynthLookAndFeel#setStyleFactory(javax.swing.plaf.synth.SynthStyleFactory)}, 69 or indirectly by way of 70 {@link javax.swing.plaf.synth.SynthLookAndFeel#load}. The 71 following example uses the <code>SynthLookAndFeel.load()</code> 72 method to configure a <code>SynthLookAndFeel</code> and sets it 73 as the current look and feel: 74 </p> 75 <div class="example"> 76 <pre> 77 SynthLookAndFeel laf = new SynthLookAndFeel(); 78 laf.load(MyClass.class.getResourceAsStream("laf.xml"), MyClass.class); 79 UIManager.setLookAndFeel(laf); 80 </pre> 81 </div> 82 <p> 83 Many <code>JComponent</code>s are broken down into smaller 84 pieces and identified by the type safe enumeration in 85 {@link javax.swing.plaf.synth.Region}. For example, a <code>JTabbedPane</code> 86 consists of a <code>Region</code> for the 87 <code>JTabbedPane</code> ({@link 88 javax.swing.plaf.synth.Region#TABBED_PANE}), the content 89 area ({@link 90 javax.swing.plaf.synth.Region#TABBED_PANE_CONTENT}), the 91 area behind the tabs ({@link 92 javax.swing.plaf.synth.Region#TABBED_PANE_TAB_AREA}), and the 93 tabs ({@link 94 javax.swing.plaf.synth.Region#TABBED_PANE_TAB}). Each 95 <code>Region</code> of each 96 <code>JComponent</code> will have a 97 <code>SynthStyle</code>. This allows 98 you to customize individual pieces of each region of each 99 <code>JComponent</code>. 100 <p> 101 Many of the Synth methods take a {@link javax.swing.plaf.synth.SynthContext}. This 102 is used to provide information about the current 103 <code>Component</code> and includes: the 104 {@link javax.swing.plaf.synth.SynthStyle} associated with the current 105 {@link javax.swing.plaf.synth.Region}, the state of the <code>Component</code> 106 as a bitmask (refer to {@link 107 javax.swing.plaf.synth.SynthConstants} for the valid 108 states), and a {@link javax.swing.plaf.synth.Region} identifying the portion of 109 the <code>Component</code> being painted. 110 <p> 111 All text rendering by non-<code>JTextComponent</code>s is 112 delegated to a {@link 113 javax.swing.plaf.synth.SynthGraphicsUtils}, which is 114 obtained using the {@link javax.swing.plaf.synth.SynthStyle} method 115 {@link javax.swing.plaf.synth.SynthStyle#getGraphicsUtils}. You can 116 customize text rendering 117 by supplying your own {@link javax.swing.plaf.synth.SynthGraphicsUtils}. 118 119 </p> 120 121 <h2>Notes on specific components</h2> 122 123 <h3>JTree</h3> 124 <p> 125 Synth provides a region for the cells of a tree: 126 <code>Region.TREE_CELL</code>. To specify the colors of the 127 renderer you'll want to provide a style for the 128 <code>TREE_CELL</code> region. The following illustrates this: 129 <pre> 130 <style id="treeCellStyle"> 131 <opaque value="TRUE"/> 132 <state> 133 <color value="WHITE" type="TEXT_FOREGROUND"/> 134 <color value="RED" type="TEXT_BACKGROUND"/> 135 </state> 136 <state value="SELECTED"> 137 <color value="RED" type="TEXT_FOREGROUND"/> 138 <color value="WHITE" type="BACKGROUND"/> 139 </state> 140 </style> 141 <bind style="treeCellStyle" type="region" key="TreeCell"/> 142 </pre> 143 <p> 144 This specifies a color combination of red on white, when 145 selected, and white on red when not selected. To see the 146 background you need to specify that labels are not opaque. The 147 following XML fragment does that: 148 <pre> 149 <style id="labelStyle"> 150 <opaque value="FALSE"/> 151 </style> 152 <bind style="labelStyle" type="region" key="Label"/> 153 </pre> 154 155 <h3>JList and JTable</h3> 156 <p> 157 The colors that the renderers for JList and JTable use are 158 specified by way of the list and table Regions. The following 159 XML fragment illustrates how to specify red on white, when 160 selected, and white on red when not selected: 161 <pre> 162 <style id="style"> 163 <opaque value="TRUE"/> 164 <state> 165 <color value="WHITE" type="TEXT_FOREGROUND"/> 166 <color value="RED" type="TEXT_BACKGROUND"/> 167 <color value="RED" type="BACKGROUND"/> 168 </state> 169 <state value="SELECTED"> 170 <color value="RED" type="TEXT_FOREGROUND"/> 171 <color value="WHITE" type="TEXT_BACKGROUND"/> 172 </state> 173 </style> 174 <bind style="style" type="region" key="Table"/> 175 <bind style="style" type="region" key="List"/> 176 </pre> 177 </body> 178 </html>