Giter Club home page Giter Club logo

Comments (6)

dukke avatar dukke commented on August 17, 2024

Hi @runiter, that's by design.

If you check out the JMetro documentation you'll see that unfortunately due to limitations in Javafx user agent stylesheets, JMetro will trump any rules set in code.

Set those rules in a stylesheet, that way JMetro rules will be overridden.

Thanks!

from jfxtras-styles.

runiter avatar runiter commented on August 17, 2024

Hi @dukke
The problem is that I don't know ahead of time what the color of various css items will be. The user will select the color from UI. So I cannot use stylesheet for these settings. Do you have any other suggestions for changing css color at runtime?

from jfxtras-styles.

dukke avatar dukke commented on August 17, 2024

Use setStyle(...) method of Node, that will trump any rules set in stylesheets.

from jfxtras-styles.

runiter avatar runiter commented on August 17, 2024

I do already use setStyle() as a workaround but the problem is that as soon as the chart is resized the color is reverted back to default. The reason for that is that resizing causes the LineChart to recreate its labels so they lose the style. I compensate for it by resetting the style as soon as I detect a resize but that causes flickering as label colors keeps switching back and forth between default color and style color. It only stops when I stop resizing. It's not a pleasant UI experience. Is there any other workaround?

from jfxtras-styles.

dukke avatar dukke commented on August 17, 2024

That's weird, it seems like a javafx bug.
If you set an inline style, via setStyle, that should trump any rules either set through code or in a stylesheet. Also, that inline style should be respected even when the layout is updated via a window resize or whatever... Unless there's something that resets that style in your code?

Another option I can think of would be to have various styleclasses in your Scene stylsheet, each setting a different color that the user can choose from. Then you add/remove a styleclass depending on which color the user chose.
Wouldn't be ideal as you would have to have a styleclass per color and the user wouldn't be able to select an arbitrary color.

from jfxtras-styles.

runiter avatar runiter commented on August 17, 2024

I don't think it's a bug because javafx charts were not designed to have their tickLabels modified directly.
That's because when chart is resized, there may not be enough room for display the initial tickLabels so they have to be recalculated and recreated.

Even without jmetro I get flickering effect. Here's the code in case you like to try it:

public class Test extends Application {

	public void start(Stage stage) {
		NumberAxis xAxis = new NumberAxis();
		NumberAxis yAxis = new NumberAxis();
		LineChart<Number,Number> chart = new LineChart<>(xAxis, yAxis);
		Scene scene  = new Scene(chart,500,200);
		stage.setScene(scene);
		stage.show();
//		xAxis.lookup(".axis").setStyle("-fx-tick-label-fill: red");

		scene.widthProperty().addListener((s, o, v) -> {
			Set<Node> nodes = xAxis.lookupAll(".axis Text");
			System.out.println(nodes.iterator().next().hashCode()); // print hashcode of first axis number
			nodes.forEach(n -> n.setStyle("-fx-fill: red;"));
		});
	}

	public static void main(String[] args) {
		launch(args);
	}
}

Your solution may work but as you said it's not ideal.
I found another workaround that is also not ideal but a little better. I need to create a subclass of javafx LineChart and override the methods so that I apply the style immediately after axis labels are created.

It works for me fine, but these issues could discourage other people from using jmetro.
I'm going to file a ticket with JDK to ask them to provide the necessary API for user-agent solution. Hope they will listen.

from jfxtras-styles.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.