包 javax.swing.plaf.synth
SynthStyleFactory
。这两个配置选项都需要了解合成器架构(如下所述)以及对 Swing 架构的了解。
除非另有说明,否则 null 不是 synth 包中定义的任何方法的合法值,如果传入将导致 NullPointerException
。
Synth
Synth 中的每个ComponentUI
实现都将自己与每个 Region
的一个 SynthStyle
相关联,大多数 Components
只有一个 Region
,因此只有一个 SynthStyle
。 SynthStyle
用于访问所有与样式相关的属性:字体、颜色和其他 Component
属性。此外,SynthStyle
s 用于获取 SynthPainter
s,用于绘制 Component
的背景、边框、焦点和其他部分。 ComponentUI
s 从 SynthStyleFactory
获得 SynthStyle
s。 SynthStyleFactory
可以直接通过 SynthLookAndFeel.setStyleFactory(javax.swing.plaf.synth.SynthStyleFactory)
提供,也可以通过 SynthLookAndFeel.load(java.io.InputStream, java.lang.Class<?>)
间接提供。以下示例使用 SynthLookAndFeel.load()
方法配置一个 SynthLookAndFeel
并将其设置为当前外观:
SynthLookAndFeel laf = new SynthLookAndFeel();
laf.load(MyClass.class.getResourceAsStream("laf.xml"), MyClass.class);
UIManager.setLookAndFeel(laf);
许多 JComponent
被分解成更小的部分,并由 Region
中的类型安全枚举标识。例如,JTabbedPane
由 JTabbedPane
的 Region
(Region.TABBED_PANE
)、内容区域 (Region.TABBED_PANE_CONTENT
)、选项卡后面的区域 (Region.TABBED_PANE_TAB_AREA
) 和选项卡 (Region.TABBED_PANE_TAB
) 组成。每个 JComponent
的每个 Region
都会有一个 SynthStyle
。这允许您自定义每个 JComponent
的每个区域的单独部分。
许多 Synth 方法采用 SynthContext
。这用于提供有关当前 Component
的信息,包括:与当前 Region
关联的 SynthStyle
,作为位掩码的 Component
状态(有效状态请参阅 SynthConstants
),以及标识 Component
正在绘制的部分的 Region
.
非 JTextComponent
s 的所有文本呈现都委托给 SynthGraphicsUtils
,它是使用 SynthStyle
方法 SynthStyle.getGraphicsUtils(javax.swing.plaf.synth.SynthContext)
获得的。您可以通过提供自己的 SynthGraphicsUtils
来自定义文本呈现。
特定组件的注释
JTree
Synth 为树的单元格提供了一个区域:Region.TREE_CELL
。要指定渲染器的颜色,您需要为 TREE_CELL
区域提供样式。以下说明了这一点:
<style id="treeCellStyle">
<opaque value="TRUE"/>
<state>
<color value="WHITE" type="TEXT_FOREGROUND"/>
<color value="RED" type="TEXT_BACKGROUND"/>
</state>
<state value="SELECTED">
<color value="RED" type="TEXT_FOREGROUND"/>
<color value="WHITE" type="BACKGROUND"/>
</state>
</style>
<bind style="treeCellStyle" type="region" key="TreeCell"/>
这指定了一种颜色组合,选中时为红底白字,未选中时为红底白字。要查看背景,您需要指定标签不是不透明的。以下 XML 片段执行此操作:
<style id="labelStyle">
<opaque value="FALSE"/>
</style>
<bind style="labelStyle" type="region" key="Label"/>
JList 和 JTable
JList 和 JTable 的渲染器使用的颜色是通过列表和表区域指定的。以下 XML 片段说明了如何在选中时指定红底白字,以及在未选中时指定红底白字:
<style id="style">
<opaque value="TRUE"/>
<state>
<color value="WHITE" type="TEXT_FOREGROUND"/>
<color value="RED" type="TEXT_BACKGROUND"/>
<color value="RED" type="BACKGROUND"/>
</state>
<state value="SELECTED">
<color value="RED" type="TEXT_FOREGROUND"/>
<color value="WHITE" type="TEXT_BACKGROUND"/>
</state>
</style>
<bind style="style" type="region" key="Table"/>
<bind style="style" type="region" key="List"/>
-
类描述可以从样式中获取的颜色的类型安全枚举。Swing 组件的不同渲染区域。为
JButton
提供 Synth L&F UI 委托。为JCheckBoxMenuItem
提供 Synth L&F UI 委托。为JCheckBox
提供 Synth L&F UI 委托。为JColorChooser
提供 Synth L&F UI 委托。为JComboBox
提供 Synth L&F UI 委托。Synth 使用的常量。一个不可变的瞬态对象,包含有关Region
的上下文信息。为桌面上最小化的内部框架提供 Synth L&F UI 委托。为JDesktopPane
提供 Synth L&F UI 委托。为JEditorPane
提供 Synth L&F UI 委托。为JFormattedTextField
提供 Synth L&F UI 委托。原始图形调用的包装器。通过SynthContext
的图标。为JInternalFrame
提供 Synth L&F UI 委托。为JLabel
提供 Synth L&F UI 委托。为JList
提供 Synth L&F UI 委托。SynthLookAndFeel 为创建自定义外观提供了基础。为JMenuBar
提供 Synth L&F UI 委托。为JMenuItem
提供 Synth L&F UI 委托。为JMenu
提供 Synth L&F UI 委托。为JOptionPane
提供 Synth L&F UI 委托。SynthPainter
用于绘制JComponent
s 的部分。为JPanel
提供 Synth L&F UI 委托。为JPasswordField
提供 Synth L&F UI 委托。为JPopupMenu
提供 Synth L&F UI 委托。为JProgressBar
提供 Synth L&F UI 委托。为JRadioButtonMenuItem
提供 Synth L&F UI 委托。为JRadioButton
提供 Synth L&F UI 委托。为JRootPane
提供 Synth L&F UI 委托。为JScrollBar
提供 Synth L&F UI 委托。为JScrollPane
提供 Synth L&F UI 委托。为JSeparator
提供 Synth L&F UI 委托。为JSlider
提供 Synth L&F UI 委托。为JSpinner
提供 Synth L&F UI 委托。为JSplitPane
提供 Synth L&F UI 委托。SynthStyle
是一组样式属性。用于获取SynthStyle
的工厂。为JTabbedPane
提供 Synth L&F UI 委托。为JTableHeader
提供 Synth L&F UI 委托。为JTable
提供 Synth L&F UI 委托。在 Synth 外观中提供纯文本编辑器的外观。为JTextField
提供 Synth L&F UI 委托。在 Synth 外观中提供样式文本编辑器的外观。为JToggleButton
提供 Synth L&F UI 委托。为JToolBar
提供 Synth L&F UI 委托。为JToolTip
提供 Synth L&F UI 委托。为JTree
提供 Synth L&F UI 委托。SynthUI 用于获取特定组件的 SynthContext。为JViewport
提供 Synth L&F UI 委托。