JavaFX Content Rendering & Resizing and Font Bugs In Linux

Siddhesh Rane siddheshrane at disroot.org
Fri Jan 18 18:13:40 UTC 2019


January 18, 2019 2:48 PM, "Ty Young" <youngty1997 at gmail.com> wrote:

> The documentation on the sizing says that they override the computed size.

Computed size refers to Region.USE_COMPUTED_SIZE which causes a node to compute its intrinsic or default size if given infinite space. Basically, you want a button with 4 characters of text to have smaller default size (min/pref/max width) than a button with say 20 chars. If anything is overridden, it is this "default" size, not the final laid out size, which is determined by the parent layout pane.

>> On your second point, it is only an issue if you use it in the wrong way, without understanding.
> 
> Excuse me? There is no documentation AFAIK stating that this would ever be an issue nor would
> anyone look at the UI and think that a GridPane is necessary to achieve such a basic layout. The
> use of GridPane seems more like a hacky workaround for something JavaFX seemingly has no other way
> to achieve with more appropriate layout management nodes(VBox, HBox, etc) without side affects.
>
> I wanted to place the buttons and Scrollpane in a horizontal fashion, so I used an HBox. I wanted
> to dynamically size the nodes based on a percentage of the window's total width/height, so I used
> property bindings to force content to the desired correct. If that causes issues then maybe all
> controls should get a supported percentage based way to set the width/height like GridPane's
> columns with appropriate layout nodes so people don't try doing this sort of thing.

There is also no documentation that uses Bindings for layout. All layout panes have been properly documented.
Using GridPane is not a hack because percentage sizing is another type of layout in itself. The only reason percentage feels basic and "seemingly simple" is because the Web has normalized it. But that is because the Web doesn't have layouts.
It simply tries to fit everything to the width of the parent and then calculates the height from reflow. What is a hack is using percentage based grids to create the illusion of having a layout. Percentage works because there is only one way in which size information flows: from main window down to child elements. Parent widths are known before hand (not heights, try setting height:100% to a div inside its height:auto parent).
In JavaFX, parent sizes and the entire size of the window can be "computed" from the child elements, because child size hints are independant on their own. Introducing percentages for controls or any other nodes breaks that property.
Read the -fx-min-width entry on the last row of Region docs at https://docs.oracle.com/javase/9/docs/api/javafx/scene/doc-files/cssref.html#region

>>> SceneBuilder's lack of UI snapping compared to Netbean's Swing builder makes it incredibly
>>> difficult to get anything remotely pixel perfect without banging your head against a wall. Separate
>>> controller classes and FXML annotations everywhere isn't really desirable either. I originally
>>> entertained the idea of doing it all in FXML only to quickly discard the idea.
>> 
>> If you are talking about snapping like in aligning to other UI elements, then its there and you
>> dont need it with the rought layout. If you mean snapping to pixels, JavaFX has it inbuilt and on
>> by default.
> 
> It is but it is incomplete. Try resizing a Button in both SceneBuilder and Netbean's Swing builder
> to the bottom right after first snapping to the top left. The button will snap perfectly to both in
> the Swing builder but not SceneBuilder.

If you need snapping in your design, then you are not doing layouts, you are drawing your UI. For the equivalent, add a button to an AnchorPane in SceneBuilder and right click the button to "Fit to parent". Watch AnchorPane Constraints in Layout tab to the right. Alternatively, add button to stack pane and set button max{width,height} to max value.

From personal experience I can say that a lot of your frustrations with JavaFX are caused due to 2 things:
- You are using your learned knowledge and concepts from Swing/HTML-CSS and applying them to JavaFX
- You have briefly walked through the JFX tutorials and then directly jumped into making one big app, instead of spending more time exploring with smaller examples.

When I was migrating from Swing to JFX, I was myself very confused and frustrated because sizing and layout didnt really work as I expected them to work. I was hand coding everything, essentially replicating what I had done in Swing. But JavaFX is different from platforms out there. Eventually I learned a lot from experimenting in Scene Builder and patiently reading the docs. I would recommend you to spend more time in SceneBuilder, at least for learning.

Regards
Siddhesh


More information about the openjfx-dev mailing list