0

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.

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...

Are there CSS parsers for JavaFX?

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;      
 }

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

2
  • You want to display the current style of a control (e.g. Label) to the user and let him provide his own definition which will update the style? Should this edited style be persisted, so it is used the next time the user starts the application? Commented Nov 18, 2015 at 9:36
  • I want to be able to edit some css properties of some nodes in my program, from my JavaFX program. What you said is partially correct, the important point is being able to edit FX-CSS from Java without having to write a CSS parser from scratch. Commented Nov 18, 2015 at 9:47

2 Answers 2

0

You can use color picker, Try this example

Hbox layout =new HBox(10);
ColorPicker colorPicker = new ColorPicker();
colorPicker.setValue(Color.RED);//Red is the default shown at first

Label label =new Label("Your Text");
layout.getChildren().addAll(label,colorPicker);

//Then
colorPicker.setOnAction(event->{
            label.setFill(colorPicker.getValue());
        });

Also for css

colorPicker.setOnAction(event->{
            label.setStyle("-fx-text-fill: "+colorPicker.getValue()+";");
        });
Sign up to request clarification or add additional context in comments.

7 Comments

Thank you, but this doesn't solve my problem, since I want to be able to directly edit the CSS file. I can't find any Java FX-CSS parsers online... Letting users choose a color isn't a problem, the problem is editing the CSS file since I don't want to write a CSS parser from scratch.
@user3804769 You can the use setStyle and also add your other styles if you wish,check out the edit.
Yes, but this doesn't edit the css file... Editing the file is what I'm looking for. I know how to edit the style of a node. Thank you :)
@user3804769 I don't think you can edit the css file dynamically after loading it to the root,may be first create css file and load it to the root and see what you get.
Yeah, the problem is still how to edit a CSS file without having to write a CSS parser from scratch... Or can you suggest a good CSS parser for Java which doesn't freak out when reading fx-css? I have tried several CSS parsers for Java, can't seem to use any. Zero documentation.
|
0

I have used CSSParser:

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

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.