JavaFX sizes doubts - javafx

If I have a window with a BorderPane and its size properties are:
Min Width: USE_PREF_SIZE.
Min Height: USE_PREF_SIZE.
Pref Width: 600.
Pref Height: 400.
Max Width: USE_PREF_SIZE.
Max Height: USE_PREF_SIZE.
Why can I resize the window? I haven't clear how works these properties (I read the API and I still don't understand).

The min/max/pref width and height of a Region are used by a parent layout pane to determine how to size and position the child nodes of that pane. So if you put your border pane in a parent which manages layout (i.e. a subclass of Pane), then those settings would be adhered to, if possible.
However, a Scene is not a layout pane and basically performs no layout. It has one root node (a Parent instance), and simply sizes the root to the size of the Scene. In turn, the scene is sized by the window and takes on the size of the window minus any space needed for a window border and decorations.
Consequently, these settings on your BorderPane have no effect on the resizability of the window. To turn off the ability to resize the window, use the window method setResizable(false). Similarly, if you want to impose minimum or maximum sizes on the window, use the window's min/max width/height properties.

Related

Determine the width of the ScrollPane scrollBar or the width of the available viewing area

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()

How to disable rendering in QML WebView?

I am currently building an application that makes use of QML WebView (import QtWebKit 3.0). The users need to resize the WebView very often (I am using a QML SplitView), however this leads to the UI to lag extremely whenever the app window is resized. Is there any way to prevent this?
Instead of changing the width and height properties change scale property of the WebView.
At beginning of the resize save initial values of width and height.
On resize don't change width and height. Instead set scale to newWidth divided by width at beginning of the resize.
When resize ends set new values of width and height to these properties and set scale to 1.
EDIT:
Since you don't have control of width and height properties you can replace WebView with Rectangle with color set to "transparent". Then you can place WebView on Rectangle and watch how width and height of Rectangle are changing.
Now two things.
If you don't know when resize starts and when ends use Timer with interval for example 100ms. Restart Timer and update scale every time width and height of Rectangle changes. When Timer is triggered set real width and height.
If ratio of width and height of Rectangle is not constant use QML object Scale. With it you can change xScale and yScale independently.

Restrict JavaFX stage resize with root's minimal and maximal sizes

I have a resizable stage with flexible layout. I'd like to prevent stage width and height from reducing below minimal width and height of corresponding root node.
I've searched over this site and found several suggestions to bind stages minWidth and minHeight properties to minWidth and minHeight properties of the root node. But Region's minWidth property is not a value of minimal width but policy for computing it. Most times it is set to USE_COMPUTED_SIZE and so actual minimal width is computed each layout pass. How can I bind actual computed minimal width and height to corresponding stage properties?

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.

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