I'm creating an JavaFX Game like "Wheel of Fortune". I use a BorderPane as root of the scene. and the right of this pane is set to contain a GridPane which in turn contain an ImageView and some other elements. I want to set the position of the ImageView (the wheel) so that only half of it is displayed. I've setLayoutX and setLayoutY to set the position of ImageView with x = X of GridPane + ImageView. X /2 (something like that), but the ImageView is not placed as expected. How should I do that???
ImageView http://imageshack.com/a/img812/6161/ynb8.png
Related
i have a problem with the Translate Transitions. I have a GridPane 7x7. In each cell there is a StackPane. Each StackPane has 3 ImageViews. If i want to change the position of the last added ImageView with a Translate Transition it moves but it moves under the other ImageViews. What do i have to do to keep it up top while the animation is running? It actually stays above if the animation goes up or left but not down and right.
TranslateTransition translate = new TranslateTransition(new Duration(animation_duration));
translate.setToX(100);
translate.setByY(100);
translate.setNode(players[old_x][old_y]);
translate.play();
Thanks
I have a GridPane (4x5), all it's cells have as child an AnchorPane which cointains an ImageView. I need to resize the image so it fully cover the cell as soon as the gridPane (and thus it's cells) change size.
I managed to resize the image correctly when the size of the cell grows, but when the cell gets tinier the image doesn't resize back.
This leads into partially covering images of the confinant cells.
Can anyone explain what i'm doing wrong or give me the instruction to implement a proper resize?
This is my code:
ImageView image = new ImageView("/dice/" + draftList.get(i) + ".png");
AnchorPane pane = ((AnchorPane)(gridpane.getChildren().get(i)));
pane.getChildren().add(image);
fitToParent(image,pane);
//method in the same class
private void fitToParent(ImageView image, AnchorPane pane) {
image.fitWidthProperty().bind(pane.widthProperty());
image.fitHeightProperty().bind(pane.heightProperty());
}
You can try to use the setPreserveRatio(boolean) function of the ImageView class to true. This will allow you to keep the aspect ratio constant.
Eg:
ImageView iv = new ImageView(/*file path*/);
iv.setPreserveRatio(true);
Src: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/image/ImageView.html
Other than this you can also try to limit the resizable property to false or set the min width and height so that the image is not partially covered
Src: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/layout/Region.html#resize-double-double-
I want add white border around ImageView.
One solution is to wrap the images in a Button.
And I try use StackPane:
StackPane stackPaneforImageActivity = new StackPane();
Image activityImage = new Image(file.toURI().toString());
ImageView imv = new ImageView(activityImage);
newActivityHBox.getChildren().add(stackPaneforImageActivity);
stackPaneforImageActivity.getChildren().add(imv);
stackPaneforImageActivity.setPadding(new Insets(10));
stackPaneforImageActivity.setStyle("-fx-border-color:white;-fx-background-color: black;");
imv.setFitHeight(30);
imv.setFitWidth(30);
But
Are there other solutions?
But the image is outside the StackPane. Why?
I am using JavaFX and I have a StackPane within a BorderPane within a TitledPane. Like so:
TitledPane->AnchorPane->BorderPane->StackPane
The StackPane is placed in the center region of the BorderPane. My problem is that when I run the app, the BorderPane is not filling the AnchorPane that is associated with the TitledPane. I have tried the AnchorPane.setBottom(), setTop(), setLeft(), and setRight() properties, setting them to 0.0 and it doesn't work. Thanks.
I have a problem with changing the location of my Button i want to set a Specific location where to put it but when i use .setLayoutX and .setLayoutY i even tried using .relocate and it is still not working am i doing something wrong? here is my sample code.
CODE
Button b1 = new Button();
b1.setText("Press");
b1.setLayoutX(100);
b1.setLayoutY(120); // this are just some randome numbers for this sample
StackPane pane = new StackPane();
pane.getChildren().add(b1);
Scene scene = new Scene(pane,500,500);
stage.setScenes(scene);
stage.show();
when i run the program the button is still in the center of the screen am doing something wrong?
Use Anchor pane or a pane to align nodes as per your layout.
StackPane, GridPane and many panes they come with inbuilt layout methods, you dont have control on locating the nodes based on x and y values.