FTPC StyleSheet

本文介绍了如何利用CSS样式表(StyleSheet)定制Swing应用程序的外观,包括定义选择器、支持的属性和组件,以及如何通过applyStylesheet方法实现个性化布局。特别关注了CSS在窗体和对话框定制中的应用和注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        FTPC可以通过将层叠样式表(CSS)应用于Form,可以为应用程序创建定制的外观,而无需更改应用程序的实现。放置在应用样式表的Form上的所有Swing和Plant Operations GUI控件都将根据样式表进行定制。

       CSS定义可以存储为List或应用程序表。

       如果希望使用StyleSheet格式化窗体,需要确保在设置窗体时Form控件名不包含下划线(_)。

       通过调用Form.applyStylesheet(字符串)方法应用StyleSheet。字符串参数是作为字符串的整个CSS定义,而不是保存CSS定义的List或应用程序表的名称。也可以将CSS定义分配给通过调用自定义Form打开的表单和对话框。applyStylesheet(String、Boolean)的方法:

  • 如果为true,那么对话框将使用与其父窗体相同的样式配置进行定制。这是默认值。
  • 如果为false,则对话框不是自定义的。

定义样式表

语法:

<selector> {

        property1:value;

        property2:value;

        ...

}

支持选择器

  • 元素节点选择器(Element Node Selector)

具有语法“CLASSNAME”,并按类名选择单个图形组件。例如,在下面的节点中,单个图形组件是一个平面按钮:

JButton, FlatButton{

        cursor:default;

        style:flat;

        border-style:raised-3d;

        height:25;

        text-align:middlecenter;

        font-style:plain;

}

  • 子选择器(Child Selector)

        具有语法“PARENT>CHILD”,并选择包含在另一个图形组件中的图形组件。例如,在下面的节点中,一个面板包含在一个嵌入式表单中:

EmbeddedForm > Panel {

        border-style:etched;

}

  • 条件选择器(Conditional Selector)

        选择符合条件的所有图形组件。目前,支持的条件是class条件和ID条件。这个选择器有语法".class"或" #id ",分别。下面的示例定义了嵌入式表单上特定状态栏的样式。

EmbeddedForm#efStatusBar > * > Edit{

        border-style:fixed-3d;

}

        可以使用星号(*)表示通用选择器。在上面的示例中,*号表示该规则适用于状态栏的任何容器中Edit类型的所有子元素。

  • 任意节点选择器(Any Node Selector)

       选择所有组件并使用关键字“*”。例如,下面的CSS部分定义了所有组件中使用的颜色:

* {

        foreground-color:rgb(0,51,153);

        background-color:  rgb(236,233,216);

        disabled-color: rgb(236,233,216);

        border-style:none;

}

注意:在定义样式表时,标识符(包括选择器中的元素名称、类和id)不能以连字符(-)或数字开头。

可以定义的CSS属性以及将受影响的Form对象和控件

CSS PropertyAffected Object/ControlCSS PropertyAffected Object/Control
above-tolerance-colorScalesControlfont-familyCControl, JComponent
alt-rowcolorDsGridfont-sizeCControl, JComponent
alternate-rowcolorsDsGridfont-styleCControl, JComponent
background-colorCControl, JComponentforeground-colorCControl, JComponent
below-tolerance-colorScalesControlheader-borderstyleDsGrid
bgimageDsGrid, FlatBase, JButton, JCheckBox, JLabel, JRadioButtonheader-fontfamilyDsGrid
bgimage-alignFlatBaseheader-fontsizeDsGrid
border-colorCControl, JComponentheader-fontstyleDsGrid
border-styleEdit, Form, JComponent, ListBox, MaskEdit, Panel, PictureBox, ProgressBar, TreeViewheightCControl, JComponent
boundsCControlin-tolerance-colorScalesControl
cell-selectionDsGridlayout-styleForm, Panel
cell-selection-backgroundDsGridlocationFlatButton
cell-selection-bordercolorDsGridnominal-marker-colorScalesControl
cell-selection-foregroundDsGridrow-heightDsGrid
column-resizingDsGridrow-selectionDsGrid
column-widthDsGridrow-selection-backgroundDsGrid
cursorCControl, JComponentrow-selection-borderDsGrid
disabled-colorCControl, JComponentrow-selection-bordercolorDsGrid
dockCControlrow-selection-foregroundDsGrid
dosagebar-bgcolorScalesControlsizeCControl, JComponent
dosagebar-fgcolorScalesControlstyleComboBox, JComponent, FlatBase
enabledCControltext-alignFlatBase
flow-alignmentForm, PanelvisibleCControl
focusedCControlwidthCControl
  z-orderCControl

CSS可接收属性值

  • above-tolerance-color

 

  • bgimage

bgimage:url(db:image); /*image 对象*/

bgimage:url(http:image.jpg);

  • bgimage-align

topleft|topcenter|topright|middleleft|middlecenter|middleleft|bottomleft|bottomcenter|bottomright

  • text-align

该属性值存在BUG,不能配置FlatButton的text-align属性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

为何生存

知识共享,共同进步!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值