How to fit ScrollPane into component bounds - javafx

I have this ScrollPane which I holds many components. I want to use the ScrollPane into many components with different size.
I solved temporary the problem using Rectangle2D
Rectangle2D primaryScreenBoundsthree = Screen.getPrimary().getVisualBounds();
But this is not working properly when I insert the ScrollPane with different components. I also tested this:
scrollthree.setPrefSize(ScrollPane.USE_PREF_SIZE, ScrollPane.USE_PREF_SIZE);
But again the result is not appropriate:
How I can fir the ScrollPane into the parent components borders?

Screen.getPrimary().getVisualBounds();
This returns you the bound of the Screen(Monitor) which you are using.
Bounds is the width and height of the Screen !
Inorder to use scrollPane to fit into your parent, don't use scrollthree.setPrefSize. You don't have to specify the size of the scrollPane, it will automatically fit into Parent
Infact, all the javafx panes fit into their respective parents !

Related

Javafx line connecting two circles in a stackpane [duplicate]

I was learning javafx and came across these two statements which I don't know their difference.
Pane pane = new Pane();
and
StackPane pane = new StackPane();
Can somebody enlighten me about the difference and when to use which?
Both are layouts but the Pane is the basis of all the other layouts, the difference is that the Pane offers a free positioning of nodes, and The StackPane (and other Node with the suffix Pane called Built-in Layout) in return, follow their own logic (Positions/Constraints...). The 'StackPane' for example lays out its children in a back-to-front stack StackPane. This is only superficial and limited information, here's a good tutorial : Layout in JavaFX
The difference between both layouts is positioning of the children and the resizing of resizeable children.
Pane does not do any positioning. The child's layoutX and layoutY are left unmodified. Furthermore resizeable children are resized to their preferred sizes.
StackPane determines the position of children based on the alignment set for the child itself or the one set for the StackPane itself, if no position is set for the child. Resizable children are resized to a size that fits the StackPane's size best (still taking into account max size). Both can be modified by a margin set for individual children...

Resizing SplitPane Programmatically

I'm trying to layout a Stage using a GridPane as the root of the Scene.
row 1 contains a HBox
row 2 contains a SplitPane with orientation set to Vertical
The SplitPane contains a browser control and another SplitPane with orientation set to Horizontal. The inner SplitPane contains two TableViews.
I'm try to have the outer SplitPane resize as the window changes size (please forgive if I'm not using the correct terms). I've seen how this can be done when using fxml but I'm restricted to using Javafx 8 and must do this programmatically. If it matters I'm using Netbeans 8.1.
It would be most appreciated if someone could point me in the right direction.
thank you
A.G.
It turns out the solution to resizing the outer SplitPane was to use the type's static setResizableWithParent method.
SplitPane.setResizableWithParent(outerPane, Boolean.TRUE);
With that addition the SplitPane resized vertically but was limited horizontally by the width of the GridPane. The grid only contains one column so setting a ColumnConstraint's PercentWidth property to 100 allows the grid and SplitPane to resize horizontally.
Try this code,
yourSplitPane.setMinSize(500, 400);
yourSplitPane.setMaxSize(500, 400);
Here, 500 is width and 400 is height.

Scaled content in JavaFX Scrollpane

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.

setMaxHeight() method not working for TextField in JavaFX

TextField t1 = new TextField();
t1.setMaxHeight(50);
t1.setMaxWidth(140);
This is the code I use to define a TextField in JavaFX. I think setMaxHeight() method is not working because size is not changing even if the value is changed.
So I tried setPrefSize(), but it too has a problem. The height property is working fine in it, but width is larger than I specified.
How to solve the above issue ?
This is very similar to how swing components work with a layout manager. In javafx the parent pane will adjust the size of nodes so a size that fits. I bet if you give the pane more room the nodes will fill out to their preferred size.

JavaFX 2 Not Resizing UI Control Based On Window Size

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.

Resources