I need a scaled ImageView with a Canvas overlay, stretched over the parent, with a constant margin on the right hand side. This suggests an AnchorPane with the ImageView and Canvas as children, each with a rightAnchor inset representing the margin.
I need to put the AnchorPane in a ScrollPane. The ScrollPane must, when resized, resize both the ImageView and the Canvas overlay within the AnchorPane, while retaining the margin.
I have tried adding the ImageView and Canvas to the AnchorPane, and adding the AnchorPane to the ScrollPane, with ScrollPane.setFitToWidth(true). When I increase the size of the ScrollPane, all works well - both the ImageView and Canvas expand to fill the ScrollPane, retaining the margin on the right hand side.
However, when I reduce the size of the ScrollPane, the size of the AnchorPane is not reducing, but instead the viewport over the AnchorPane is reducing, with increasing scrollbars.
NB, an ImageView inserted directly into the ScrollPane does work - it rescales both on grow and shrink.
It looks as though ScrollPane.setFitToWidth behaviour differs depending on the container inside the ScrollPane.
Is this correct, and can anyone suggest a solution, please?
Robert
Try adding a listener to one of the ScrollPane's Bounds properties and reduce the AnchorPane's size from there when appropriate.
Solved using Jurgen's answer.
I overrode AnchorPane.computeMinHeight, computePrefHeight and computeMaxHeight to return imageView.minHeight, prefHeight and maxHeight. This ties the anchor pane's height to the imageView's height - which the imageView calculates from its own width.
Then I added a listener to the scrollPane.widthProperty which calls the AnchorPane.setPrefWidth, setMinWidth and setMaxWidth
In this way, the anchor pane is correctly signalling its preferred, minimum and maximum width to the enclosing scrollPane.
Related
I'm trying to make an imageview fit the size of its container (in my case a Pane), and at the same time place it in the center of the Pane in JavaFx, in detail I can't do both at the same time i can get it to fit the container, but not put it in the center.
here is the code i use to make it fit in the container Pane
//imgContainer is the pane that contains the image
//photo is my imageview
photo.fitWidthProperty().bind(imgContainer.widthProperty());
photo.fitHeightProperty().bind(imgContainer.heightProperty());
photo.setImage(new Image(post.getPhoto()));
this is the output that is produced, the photo adapts to the Pane dimensions, but it is located to the left of the container(the dark background is the Pane container) would to put it in the center of the pane and i couldn't find a method to do it keeping the dimensions of the Pane for the imageview, putting it on a hbox or stackPane allows to put it in the center but the image no longer keeps the container sizes well, so i don't know how to get it centered and fits the container at the same time
I need to set the Min, Max and Pref width of the Pane contained inside of a ScrollPane to a single value (preferably the size of the ScrollPane's available viewing area).
If I just bind it to ScrollPane width, once the Scrollbar appears on the ScrollPane it overlays some of the underlying pane.
Is it possible to somehow determine the available width inside of the ScrollPane(i.e. full width minus the Scrollbar width) and monitor it for changes?
I just found the answer. I can use the scrollPane.viewportBoundsProperty()
i've got following problems.
How, in FXML, put for ex. 3 TitlePanes into ScrollPane, in such way, that when i open all 3 TitlePanes, the vertical scroll will appear, but when i have for ex. 1 open it disappear? (fit ScrollPane height to it's dynamicaly changing content)
How, in FXML, put TilePane into TitlePane, that TitlePane will fit to it content? For ex. i put 4 Buttons into TilePane. At begining it's 2x2. When i reduce width, it change into 4x1, TilePane heigth grow, but TitlePane doesnt grow with it, and not all Buttons are visible. How to connect TilePane size with its container TitlePane size?
I'll be appriciate for any help.
If you are using FXML, make sure that you do not set the preferred height of the controls you want to resize, they should be set to COMPUTED. With this set, a collapsed TitledPane will only take up the size of it's title.
I'm new to JavaFX and I want to learn. I have a Group containing a GridPane that contains a lineChart, TableView and HBox (status bar) but I'm experiencing the following problem:
I am using screen resolution 800 x 600 on Windows XP when I change the screen resolution to 1024 x 768, the lineChart, TableView and HBox does not expand to fill the new window size, it leaves a large space at the right. How can I make controls fill the width of the window when window is resized.
The TableView's height extends beyond the boundary of the window, the bottom border of the tableView and the status bar is not showing. How can I make sure that the tableView does not extend beyond the window height?
How can I make controls fill the width of the window when window is resized.
Instead of using a Group as the root of your Scene, just make the GridPane the root of your scene.
The layout Pane classes automatically expand and shrink to fit their available area as the area changes whereas a Group does not.
How can I make sure that the tableView does not extend beyond the window height?
Your scene will probably end up being completely enclosed in the window if you just make the change above and use a layout pane as the scene root.
Additionally, if the sum of the minimum sizes of the window elements is greater than the window size, then the TableView will extend beyond the boundaries of the window, in which case you can either reduce the minimum sizes of elements (by using smaller fonts or less text, explicitly setting minWidth/minHeight values etc.) or wrap elements in a ScrollPane - but in your case those modifications are probably unnecessary.
you should use userComputed size (height,and width) property.
I have a problem in flex scroll bars. I have a mxml component based on canvas. Inside that I have used a VBox for my form. Above that Vbox I have another canvas just for title.
My form gets longer than normal screen size when the grid inside that is filled with more data. In that case I want a vertical scroll bar just for Vbox in which my form is located. But the whole canvas is getting scrollbar including title canvas. how to solve this problem.
I set vertical scrollbar policy of main canvas to off and inside Vbox's VerticalScrollbarPolicy to on. but that's not working. It is not overriding the property of parent container.
Thanks.
Keep your Form inside a Canvas inside the parent canvas instead of VBox. VBox and HBox are set to grow automatically in the parent container, so if your form grows, your corresponding VBox will grow as well.
You want to overload the "updateDisplayList" function for your parent canvas, and force the height of your form Vbox to be canvasHeight-titleHeight (including padding, space, etc...) so that the VBox never grows larger than the screen. This will solve your problem. Just make sure you check for the existence of the VBox as sometimes the updateDisplayList will be called before it has been instantiated.
Had the same problem myself and decided to take the easy route.
Have the following
App->vbox->[vbox + hbox]
components are dynamically being added to last vbox. Wanted hbox to stay on screen and have scrollbars only in vbox above it(2nd vbox).
Was experiencing the same problem. All containers had scroll policy=off except for last vbox, but when dynamically adding components, when the components filled the vbox > 100%, the outer vbox would start to scroll.
Resolution was simple once I went back to the documentation.
Set scroll policy - horizontal and vert on app and first vbox to off, and also added autoLayout=false. This causes the engine to not resize the components after initialization, ie, they are static sized.
Once I added this property, no more scrollbars except for the inner vbox.
Tada!