Cannot see stylesheet effect in JavaFX Scene Builder? - css

Q1. I've set the background image for my BorderPane using a CSS stylesheet(style.css).
When I run the application, the background works, but I'm not able to see the background while working in Scene Builder. Why is that?
CSS code:
.root {
-fx-background-image: url("grey.jpg");
}
Q2. Also how can I achieve this with just setting the style for BorderPane instead of using a stylesheet? I've tried:
But that doesn't change the background while running the app or in Scene Builder.

Related

How do I change the header color of a TabPane in SceneBuilder?

I want to change the header color (the grey one) on SceneBuilder. I've tried changing the background but it only changes the frame, not the top of the tab.
I'm kinda new into JavaFX and CSS, so I don't know how to change it manually with CSS. Here's what I want to change:
I want to change the gray bar to blue.
You can change the header background for the TabPane using the appropriate CSS selector:
.tab-header-background {
-fx-background-color: blue;
}
Result:
As far as I know, the only way to have the new style show up in SceneBuilder is to create a .css file with the code above, and then import it into SceneBuilder for your root element (for instance, a top-level AnchorPane):

JavaFx & TornadoFX changing margin in CSS or TypeSafeCSS

Can i set hbox constraints(margins)in TypeSafeCss in TornadoFx or Css for JavaFx?
hbox {
textfield {
hboxConstraints {
margin = Insets(5.0)
}
}
}
How to do this with CSS or TypeSafeCSS without using padding.
As of the information of now thx to #fabian this is not possible in JavaFx
It is not possible so far.
Because TornadoFx depends on JavaFx
If JavaFx cant do it also TornadoFx cant.
Yes it might be possible with TornadoFx with a lot of tricks and tweaks but i/you would have to touch the JavaFx source code.

JavaFX Context Menu stops Parent's Transparent Background

So, I've been programming an analog clock in JavaFX and have gotten the base functionality down. Now, I'm trying to add a drop-down menu when I click a custom button (triangle made with a Polygon). So far it all works fine, except the fact that the background of my StackPane is white when I try to add a ContextMenu either before or after clicking the button. So far Transparency has been fine up until now. Here's some pictures of the issue.
This is what it should look like (you can see my wallpaper because of the transparent window, as it should be.)
enter image description here
After I press the button for the drop down menu, the background changes.
enter image description here
JavaFX controls are styled by CSS. The first time you create a control, the default user agent stylesheet (modena.css) is loaded and the styles defined in it are applied to the scene graph. Other JavaFX node classes, such as shapes, image views, and layout panes, do not enforce CSS loading (this is to enhance performance for graphically-intensive applications that do not need CSS).
So it sounds as though the context menu is the first control you create: when you create and display it, it will apply the default CSS to the scene. The default background color for the root pane is a non-transparent color, so while your Scene and Stage may be transparent, once the CSS is applied the scene's content is not.
The fix is to specify transparency for the root pane:
root.setStyle("-fx-background-color: transparent;");
or the equivalent in an external stylesheet.
To answer my own question in case anyone else wants to know, it seems that when the ContextMenu is added to the scene, the Stage's initStyle(StageStyle.TRANSPARENT) gets overridden and shows the Parent's colors. Since I didn't initialize any CSS styles for the root, it just showed white. The fix would be to:
//the Parent layout Pane
parent.setStyle("-fx-background-color: rgba(0, 0, 0, 0.0)");

JavaFX transparency bugged? [duplicate]

I had a hard time figuring out why my transparent stage refuses to be transparent. Finally I found out, that it was caused by a Tooltip that was installed into an ImageView:
ImageView imageViewIcon = new ImageView();
imageViewIcon.setFitWidth(70);
imageViewIcon.setFitHeight(70);
imageViewIcon.setPreserveRatio(false);
imageViewIcon.setImage(new Image("./next.png"));
Tooltip tooltip = new Tooltip("Tooltip!");
if (this.config.getShowTooltip("true")) {
Tooltip.install(imageViewIcon, tooltip);
}
When I comment out the last 4 lines, the transparency works as expected, but with the Tooltip installed the stages background is grayish (e.g. the default window background). Though it's obvious what the button does and the tooltip is not essential for my layout it'd be nice to have, just to give a little hint...
Any suggestions or workarounds?
Solution
Set the style -fx-background-color: transparent on the root node of the scene.
Background
Similar behavior is discussed in an Oracle JavaFX Forum post on the JavaFX Scene/Fill Color.
Relevant comments from the thread by David Grieve, the lead developer for the JavaFX CSS features:
This happens because modena.css sets the background color of the root node. Setting the style -fx-background-color: transparent on the root node of the scene is the solution.
BorderPane root = new BorderPane();
root.setStyle("-fx-background-color: transparent;");
Scene scene = new Scene(root, 600, 400, Color.BLACK);
The default user agent stylesheet is loaded the first time a Control is instantiated. The reason for this is to avoid loading stylesheets and reduce CSS overhead in scene-graphs that contain nodes that don't use CSS.
The history behind it is that the designer of the modena theme felt that the controls looked better on this particular background color, which is a very light grey. Unfortunately, the Scene's background fill cannot be styled from CSS, so the style was set on the root node of the scene. There is an issue logged in JIRA to make Scene so that it can be styled by CSS (RT-31282)
The merit of loading in this way is to avoid css overhead in scene's that don't use controls. This would be typical of a splash screen, for example. Or maybe a game. This design choice was made a long time ago when CSS performance was a big issue, but it still makes sense for embedded devices.
In the case of your question, Tooltip is a control, so when you add it to the scene it implicitly triggers the default modena.css stylesheet to be loaded for the scene (which sets the background of the root node of the scene to gray rather than a null or transparent fill which is used when there are no controls in the scene). To retain the transparent background for the application when a control is used in the scene, it is necessary to explicitly set the scene root node background to transparent.
Sample code for a transparent stage:
//this is where the transparency is achieved:
//the three layers must be made transparent
//(i) make the VBox transparent (the 4th parameter is the alpha)
root.setStyle("-fx-background-color: rgba(0, 0, 0, 0);");
//(ii) set the scene fill to transparent
scene.setFill(null);
//(iii) set the stage background to transparent
stage.initStyle(TRANSPARENT);

How to change the Scene Builder background image(default is Blue Grid)?

The default background image of Scene Builder is Blue Grid as shown below.
Can I change this background image or color of Scene Builder to some other color or image apart from the in built ones (i.e. Neutral Grid and Neutral Uniform)?
To change the default colors in SceneBuilder, you probably need to check out the source of SceneBuilder, modify the css stylesheet in the SceneBuilder source tree and rebuild the SceneBuilder application.

Resources