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

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.

Related

Cannot see stylesheet effect in JavaFX Scene Builder?

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.

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

Why can't I set AnchorPane's resizable attribute?

I created a FXML file using JavaFX Scene Builder 1.1. An AnchorPane is created by default. Why can't I modify the resizable attribute?
Do you want to disable window resizing? If so, you can do that in your application program:
stage.setResizable(false);
Why you can't edit bounds
Checkout the javadoc on layoutBounds and boundsInLocal. You will notice that both are ReadOnlyObjectProperties, which is why you can't directly modify them in SceneBuilder.
How to resize a node in SceneBuilder
You can indirectly effect the bounds properties and directly set the resizable properties of the node by altering the min, pref and max height and width.
You can also set the pref size by selecting the pane to be resized and dragging the resizing anchors the surround the selected pane.
Further Information
You might want to read the Oracle tutorial on Tips for Sizing Nodes and Amy Fowler's presentation on JavaFX layout.
You can change resizeble using code
primaryStage.setResizable(false);

Set the background color of a ScrollPane in JavaFX 8

I cannot set the background color of a ScrollPane in the latest version of JavaFX 8 (java 8 b-110 and above versions). So I need to know whether this is a permanent issue or temporarily (which can be Fixed in later versions)?
I ended up using -fx-background:green; instead of -fx-background-color:green; because -fx-background-color only set the colour for the borders of ScrollPane.
It looks like some additional CSS is needed in order to be able to set ScrollPane backgrounds to whatever color you like. See this question:
ScrollPanes in JavaFX 8 always have gray background
May be This Can Help..
JavaFX ScrollPane border and background
..
JavaFX Hide ScrollPane gray border
....
JavaFX ScrollPane showing objects outside of viewport
....
JAVAFX 2.0 How can i dynamically change the content in a scrollPane?

Resources