Comments (6)
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.
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.
Use setStyle(...) method of Node, that will trump any rules set in stylesheets.
from jfxtras-styles.
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.
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.
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)
- Button, ToggleButton - Button does not show border on hover when it is focused HOT 1
- Maven Central Repository Does Not Install Correctly HOT 2
- TextField - TextField with "glitched" background when disabled and inside Dialog
- TextFields - Non-Editable TextFields shouldn't have a 'clear' button HOT 2
- Exception "Failed to load skin 'impl.jfxtras.labs.internal.scene.control.skin.ListSpinnerCaspianSkin'" HOT 2
- JMetro NPE when getOverridingStylesheets().add(source). Should throw instructive exception HOT 2
- JMetro: NoSuchMethodError with no code written HOT 16
- DatePicker - changes height when focused HOT 2
- Spurious classifier tags in dependencies in pom.xml HOT 3
- Style a WebView Web Page using JMetro Theme Style HOT 1
- JMetro: JavaFX 16 JDK17 NullPointerException HOT 3
- Some suggestions of Jmetro on Windows 11 HOT 1
- TreeView, TableView, ListView, TreeTableView - not sure if we need styles for pressed:selected and pressed
- New windows ui (winui3) implement HOT 1
- ProgressBar - Switching from indeterminate, to real and finally back to indeterminate doesn't animate
- Scrollpane shrink contents when focused
- Wrong Spinner text color inside TabPane HOT 5
- JFXCentral Badge
- The setFill for the Text component does not execute correctly HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jfxtras-styles.