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.
"
Related
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
Link to screenshots: https://imgur.com/a/uSpTG8I
First image is when the window is expanded, second one is when the program runs. The others is of the FXML file and the scenebuilder program.
I have looked this up and tried the various layout options in the scenebuilder program itself but none of them works as I wanted. I want the image to stay centered, and if possible, the arrow buttons to also be centered.
Thanks
I'm a fan of BorderPanes. If you wrap your arrows to the Center of the BorderPane they will stay centerd, even if you resize your Scene.
So if You want the arrows and the big Image Centered use a BorderPane and wrap the Image to the Center. Now you can wrap another BorderPane in parent BorderPane's Bottom and wrap your Arrows to center.
I have dynamically created a bunch of buttons. I gave a fixed width to each of them. I want it to be added until space is available to its parents and when it overlaps with some other nodes, it will automatically go to the next line in order to avoid collision. I want it to be responsive at different screen sizes.
for(Data i:datas){
Button btn=new Button(i.getName());
anchorPane.getChildren().addAll(btn);
}
I want to arrange the buttons in a new line only when the buttons in the first line have covered its total width. How can I accomplish it? Any help is appreciated.
James_D provided a great resource—there's a built in layout for anything you need and FlowPane has what you want here.
Using your example, just swap out your AnchorPane for FlowPane:
FlowPane flowPane = new FlowPane();
for(Data i:datas){
Button btn=new Button(i.getName());
flowPane.getChildren().addAll(btn);
}
To make it responsive (i.e. expand and contract with the parent container/stage), bind the FlowPane's width and height to those of its parent:
flowPane.prefWidthProperty().bind(stage.widthProperty());
flowPane.prefHeightProperty().bind(stage.heightProperty());
I have this problem:
I am using javaFX and scene builder (2.0) and I have placed scrollPane into my window, which in turn contains anchorPane. When I start my application everything works ok, but when I programmatically/dynamically add nodes into the anchorPane, for some reason whole layout of my app gets weird/buggy. Basically everything stays in the prefWidth and prefHeight and does not resize when resizing the app's window, while before adding for example Polyline into the anchorPane there wasn't any problem.
It affects practically all nodes (menubar, vertical toolbar) which aren't even in the anchorPane...
here is piece of my code:
//initialize function of my cotroller class
anchorPane = new AnchorPane();
anchorPane.getChildren().add(canvas);
scrollPane.setContent(anchorPane);
...
//dynamic node insert
Polyline polyline = new Polyline(...);
...
anchorPane.getChildren.add(polyline);
//and now the whole app's layout is bugged
Thanks for answers.
I managed to fix it by changing AnchorPane to Pane.
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.