How to add shadow to window in JavaFX? - java

I have removed the default borders around the primary stage:
stage.initStyle(StageStyle.UNDECORATED)
This removes the window borders which is what I want, but now I'd like to have a drop shadow under the window.
The top level BorderPane object has a dropshadow effect applied, but the shadow is cut off:
You can see the shadow slightly on the bottom right, but as soon as the main application area ends the shadow is cut off.

I created an example for this earlier. Use the specific revision linked as in later revisions I dropped the shadow effect from the dialog.
The sample places the stage content in a StackPane containing two panes. The shadow is only applied to the background Pane and the dialog content is placed in a top pane. The background of the top pane is slightly inset from the bottom pane so that the background and shadow can show through.
Further discussion is in a thread on displaying a shadow around an undecorated/transparent stage.

Related

How to make a widget appear smoothly while keeping the anchor

I want to show a Pane whenever I click a button. The hard side is that I whant the pane to come out smootly for exemple by using a ScaleTransition from width=0 to width=100 but I whant my pane to be sticked to the side of the frame like you would normaly do with a widget inside an anchorPane.
I've tried to apply simutaniusly both a TranslateTranstion and a ScaleTransition. So the pane seems to expend to his right side. But one these transitions are done, the pane keeps its width and is not resized when the window is.
Slaw has answered my question in the comment section so I post his answer.
Would using TranslateTransition and a clip on the parent work for you? Just keep the child out of the clipped area, then translate it into the clipped area when you want to show it

Scene Builder: How to hide borders on panels, etc

I'm just starting with Scene Builder and java. I've laid out my main GUI but when I preview it, it has wide borders for all my h/v boxes, anchor panels, etc. How do I hide the borders when I actually run (preview) my UI? Is there a way in scene builder (preferred) or will I have to code this instead?
Default border on layouts
There is NO default-border on layouts which can be visible. In case, you need to remove border from layouts you can set css code using setStyle() method,
yourPane.setStyle("-fx-border-width: 0px");
You can also use external css document for styling components.
Wide border on preview
Actually, the fxml preview means that showing your design in a window. So you might get confused with window frame border as shown in the below preview,
But you can make borderles- window by styling your stage using initStyle(),
primaryStage.initStyle(StageStyle.UNDECORATED);
You can also use TRANSPARENT style as well but you have to manage your title bar for customized-window.
(source: makery.ch)

How to keep JavaFX MenuBar in the top part of the window

I'm trying to make an window, where I have StackPane as root and I want to add MenuBar to this window. However MenuBar is in the center of the screen and I want to keep it in the top part of the window as in normal Windows applications.
root = new StackPane();
root.getChildren().add(new MenuBar());
this will show window like this
http://i61.tinypic.com/2pzblmo.jpg
Thanks you for your advice!
I would say StackPane is not suitable for making a GUI including a menubar.
StackPane will just put the controls you add to it one on top of the other.
In java docs you can find:
"StackPane
The StackPane layout pane places all of the nodes within a single stack with each new node added on top of the previous node. This layout model provides an easy way to overlay text on a shape or image or to overlap common shapes to create a complex shape. Figure 1-6 shows a help icon that is created by stacking a question mark on top of a rectangle with a gradient background.
"

JavaFx-- positioning components in SceneBuilder

I used the drag and drop interface to put the components where I want them to be, but when the window is resized they lose their relative position. I have attached a screen shot of my hierarchy and of two windows to show how the components lose their position.
Hierarchy
Fullscreen
If you want to use the AnchorPane to layout your components, you can set the Anchor Pane Constraints, like in the image below:
This way it doesn't matter if you resize the screen, the button will always stay 10px far from the AnchorPane's right border.
When you use the AnchorPane to place components on screen you are not going to have a relative positioning, You should use others containers to layout your application. Read more about how to use Layout Panes here: Using Layout Panes
You need to study how to use Layout Panes. Dragging and dropping components results in absolute positioning, which really bad practice.

Fix swing element position relative to parent

I have layered pane in swing application and in that layered pane I am displaying another pane. I have used setBounds method of pane to display pane in right bottom corner of layered pane but when I maximise the application window the pane remain on its specified coordinates which spoils the look of application in maximise mode, I want it to change its location and remain in right bottom corner of layered pane irrespective of main frame size.
So is there a way to get size or coordintes of layerd pane and use that to keep child pane in layered pane's right bottom corner, even if we adjust size of main window child pane should always remain in right bottom corner of layered pane
"By default a layered pane has no layout manager," but you can use one of the standard Layout Managers or write your own.

Categories

Resources