JavaFX-以编程方式编辑或解析FX-CSS文件 [英] JavaFX - edit or parse FX-CSS file programmatically

查看:78
本文介绍了JavaFX-以编程方式编辑或解析FX-CSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JavaFX 8u60.我想让我的用户有机会在不使用外部编辑器的情况下为程序中的窗格编辑CSS文件.

I am using JavaFX 8u60. I want to give my users the chance to edit a CSS file for a pane in my program, without using an external editor.

例如,用户单击标签",然后显示一个对话框以选择颜色.用户选择颜色后,实际上会将颜色写在CSS文件中的相应行中.

For example, the user clicks on a Label, and a dialog to select the color is shown. After the user selects the color, the color is actually written in the CSS file, in the appropriate line...

是否有JavaFX的CSS解析器?

Are there CSS parsers for JavaFX?

我无法向您显示任何Java代码,因为我不确定这可以做到.

I can't show you any Java code because I'm not sure this can be done.

 .table-view .column-header .label{
    -fx-font: 18 GatwickSans;
     -fx-text-fill: red; //<--- user shall be able to edit this line from my program
     -fx-alignment: TOP_LEFT;      
 }

澄清一下,我希望能够从Java编辑FX-CSS文件.

edit: to clarify, I want to be able to edit a FX-CSS file from Java.

推荐答案

我已经使用CSSParser:

I have used CSSParser:

http://sourceforge.net/projects/cssparser/

它具有足够的通用性,并且有点像DOM XML解析器.它读取CSS文件并将其映射到内存中,从而使您可以读取单个选择器,属性和值,并进行编辑.由于缺少文档,请查看Sourceforge上的讨论,以获取一些示例.

It's sufficiently generic and it works a bit like the DOM XML parser. It reads the CSS file and maps it in memory, allowing you to read the single selectors, properties and values, and edit them. Check the discussion on Sourceforge to have some examples, since it lacks documentation.

这篇关于JavaFX-以编程方式编辑或解析FX-CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆