JavaFX 2 Not Resizing UI Control Based On Window Size - javafx

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.

Related

Responsive CheckBox JAVAFX

This is my first javaFX project. The project I'm working on includes a feature where the application window can be resized. Upon resizing the window, I expect all objects in my window to increase proportionally according to the window resize. I am not getting this to work with the "CheckBox" Objects.
As you can see below highlighted in red, a CheckBox object is shown before and after a window resize. Before the resize the red checkbox nicely fits in the green box, but after the resize, the red checkbox is the correct (scaled) width, but did not increase in height as I'd expect. Where should I begin my effort to make my CheckBox objects more vertically responsive?
Minimized
Maximized
As you can see (IN RED), the CheckBox scales horizontally as I expect, but it doesn't scale vertically to occupy the remaining space!
After a lot more research and helpful responses, I gathered a solution that works.
A "DoubleProperty" object is made, and binded to the width of the container holding my checkboxes. Call this container, "dryLeafGridPane" for example.
DoubleProperty checkboxFontSize = new SimpleDoubleProperty(10);
checkboxFontSize.bind((dryLeafGridPane.widthProperty().divide(36)));
The .divide(36) scales the CheckBox's font size to 1/36 the gridpane's width.
Finally, I just add the new font size using CSS.
dryLeafGridPane.styleProperty().bind(Bindings.concat("-fx-font-size: ", checkboxFontSize.asString()));
Here is a gif of the (slightly more) responsive app!
You can choose to increase the font size on the root pane when you go full screen. For example:
rootPane.setStyle("-fx-font-size: 150%;");
That isn't perfect though... it seems the size of the box that is checked doesn't scale with the font.

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

JavaFX sizes doubts

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.

Qt: Why children widgets overlapping in QGridLayout?

I have an widget x with fixed size. Then at first I took a QScrollArea and then a QGridLayout which I set as the layout of scrollAreaWidgetContent. Then I started adding some widget x in the layout at (0,0), (0,1), (1,0), (1,1)... of grid layout. Then when I ran the program, strangely when I shrink the window vertically, the widgets overlap.
And as expected, when I increase the window size vertically, they are not overlapped anymore.
But strange thing is this problem does not occurring when I shrink window horizontally. For example,
My question is, why this is happening and more importantly, keeping in mind I want to use gridlayout, how to solve this problem?
As you said in your question:
Your widget has a fixed size, so the layout does not shrink them when there is no space left.
So the question is: what do you want to happen when you shrink the window?
If you want to shrink your widget you have to change the sizePolicy of your widgets from "Fixed" to "Preferred".
If you want to reduce the number of widgets in the layout, then you could add an event handler in the resize event and remove them
If you want to disallow the shrinking of the window, then you need to set the sizePolicy of the scrollarea to a fixed or minimumSize

[JavaFX][FXML] Scrollpane filled by titlepanes. TitlePane filled by TilePane. (Changing container size due to changing element inside)

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.

Resources