How to Center Image and buttons/polygons? - java

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.

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

JFX scale image up and down to parent

I am attempting to have an ImageView that scales with its parent. I have searched through every StackOverflow post I can find on this, and here is what I've tried:
taggedImage.setPreserveRatio(true);
//taggedImage.fitWidthProperty().bind(
// Bindings.min(imagePane.widthProperty(), imagePane.widthProperty()));
//taggedImage.fitHeightProperty().bind(
// Bindings.min(imagePane.heightProperty(), imagePane.heightProperty()));
taggedImage.fitWidthProperty().bind(imagePane.widthProperty());
taggedImage.fitHeightProperty().bind(imagePane.heightProperty());
The commented lines I tried as well and the issue with these approaches is that when the imageview binds to the parent, the parent can only scale up and not down. Therefore, if you increase the size of the window, the picture will get bigger. If you decrease the size of the picture again, it doesn't decrease the picture size. In this example, imagePane is a StackPane. I have also tried a borderFrame. As well, I've tried using a Pane as the parent. This way, the image successfully scales up and down. However, the image isnt centered and is always in the top left corner of the pane if it doesnt match the size of the pane exactly.
Scene Tree:
https://gyazo.com/45e0daebbfd98dfd3446185d21eb91ee
Values:
Top gridpane:
https://gyazo.com/f48ebb39f48d876a02d44792a73eaad4
lower level gridpane:
https://gyazo.com/3399d9f3ab00e8babd36ee3b0e3b27ba
BorderPane:
https://gyazo.com/51c24f8de50ae3865a299fdddf3a1490
ImageView:
https://gyazo.com/7dfc1071d2b516a83baed301596be2b9
Note, here I'm trying it with a borderpane instead of what I was using before. However, the result is the same no matter which object is the parent of the imageview.
Solved. I've been messing around and found a fix. This isn't exactly intuitive but it worked for me: I left the image inside the borderframe and, in the java code, I created a pane in the same part of the gridpane as the image. I then bound the imageview's width and height to the pane. Then, the centering of the image was correct as well as the scaling.
Here is what i did:
imageView.setPreserveRatio(true);
Pane pane = new Pane();
testGridPane.add(pane, 1, 1);
imageView.fitWidthProperty().bind(pane.widthProperty());
imageView.fitHeightProperty().bind(pane.heightProperty());

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.

Node setMouseTransparent Exceptions

If I have a VBox with 3 buttons and make the VBox mouse transparent, how can I ensure that its children won't be made transparent? I need the buttons to be clickable.
I'm trying to make a clock, and my solution so far is to have a StackPane. Add 12 VBoxes in the StackPane, make it as large as the StackPane, and rotate it around the center axis 30 degrees * n. Unfortunately, the VBoxes block the layers beneath it all the way up to the top of the StackPane.
The answer was to set each VBox's pickOnBounds property to false. Since a VBox is really a blank container with no geometric shape, disabling the pick on bounds renders the VBox invisible while leaving its children intact.

Categories

Resources