0

I would like to have a Flowpane layout of items irrespective of the size of the parent of the Flowpane

From what I understand, calling setManaged(false) on any region should cause the parent to not size the region and cause the region to become its own layout root.

However if I attempt this with

Pane
 -FlowPane
  -label
  -label
  -label

where the flowpane has managed set to false and min/max/pref width and height all set to absolute values, In my example 200 pixels, then I would expect to see the Pane have its set size and the FlowPane to be sitting wherever i place it with a height and width of 200. This is not the case.

here is a barebones example. While the labels render outside of their parent flowpane, the flowpane computes a width and height of 0, so the wrapping logic for a wider flowpane will never allow anything less than wrapping every item like a stackPane.

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.Pane?>

<Pane prefHeight="500.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <FlowPane alignment="CENTER_LEFT" managed="false" maxHeight="200.0" maxWidth="200.0" minHeight="200.0" minWidth="200.0" prefHeight="200.0" prefWidth="200.0" translateX="120.0" translateY="120.0">
         <children>
            <Label text="fdsfdfdsfdsfds">
               <graphic>
                  <Pane maxHeight="10.0" maxWidth="10.0" minWidth="10.0" prefHeight="10.0" prefWidth="10.0" style="-fx-background-color: red;" />
               </graphic>
            </Label>
            <Label text="dfdfdsfsdf">
               <graphic>
                  <Pane maxHeight="10.0" maxWidth="10.0" minWidth="10.0" prefHeight="10.0" prefWidth="10.0" style="-fx-background-color: red;" />
               </graphic>
            </Label>
            <Label text="dfdfsd">
               <graphic>
                  <Pane maxHeight="10.0" maxWidth="10.0" minWidth="10.0" prefHeight="10.0" prefWidth="10.0" style="-fx-background-color: red;" />
               </graphic>
            </Label>
            <Label text="fdsfds">
               <graphic>
                  <Pane maxHeight="10.0" maxWidth="10.0" minWidth="10.0" prefHeight="10.0" prefWidth="10.0" style="-fx-background-color: red;" />
               </graphic>
            </Label>
         </children>
      </FlowPane>
   </children>
</Pane>

What could explain this lack of a local size?

Jody Sowald
  • 342
  • 3
  • 18
  • The size ranges for a resizable node (`min`,`pref`, and `max`) are used by the parent node to choose a size for that node during the layout. However, `managed=false` explicitly tells the parent not to manage the size (or position) of that node. So there is nothing which will every query those sizes. It's not really clear what you're trying to achieve here. – James_D Feb 27 '23 at 16:32
  • 1
    I suppose, to attempt to clarify: *"From what I understand, calling setManaged(false) on any region should cause the parent to not size the region"*. This is true, but in that case the `FlowPane` will *never* be sized, and consequently it will always have size zero. On the other hand, the only thing a `Pane` will do in laying out its *managed* (and resizable) child nodes is to size them to their preferred sizes, which is exactly what you want in this case. So all you really need here is to leave it as a managed node. – James_D Feb 27 '23 at 18:09
  • All that said, it's usually (if not always) a very bad idea to manage layout yourself, in any way. Why don't you want to let the `FlowPane` be responsible for calculating its own min/pref/max sizes and let its parent position and size it per the amount of space available? – James_D Feb 27 '23 at 18:11
  • My intention is to let the parent pane dictate only the width of the flowpane and then set the parent pane's height equal to the flowpane's calculated height, I want the flowpane to manage itself, i just dont want the parent pane to constrain it in both dimensions, though from the sound of what you've said that is exactly what the plain Pane accomplishes. I can just manually bind the parent pane's width to my flowpane. – Jody Sowald Feb 28 '23 at 19:12
  • It sounds like you're missing something here about how JavaFX layout works, but I don't know what it is. It's a top-down layout, so the scene allocates all its space to the root node, and then the root node calculates the size and position of its child nodes based on its layout policy and settings, and the min/pref/max size of each child node. Then, having been allocated a size, each child node similarly performs its own layout independently. So: *"I want the flowpane to manage itself"* that's what it does, by default. – James_D Feb 28 '23 at 19:21
  • as to "Why?", I actually have a 90 degree rotated flowpane. so the width of parent needs to become the height of the flowPane. – Jody Sowald Feb 28 '23 at 19:23
  • And: *"let the parent pane dictate only the width of the flowpane" ... "dont want the parent pane to constrain it in both dimensions"* This is just a case of using the correct parent pane, with appropriate settings (exactly what depends on what other nodes are in the parent pane). However: *"set the parent pane's height equal to the flowpane's calculated height"* you can't really do this; though of course there are various ways to arrange for the parent pane's *preferred* height to be equal to the flow pane's height. – James_D Feb 28 '23 at 19:24
  • I think the tricky bit of what I'm asking for comes in with that rotation. Sorry i didn't mention as much earlier. – Jody Sowald Feb 28 '23 at 19:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/252203/discussion-between-jody-sowald-and-james-d). – Jody Sowald Feb 28 '23 at 19:25
  • 1
    *"I actually have a 90 degree rotated flowpane. so the width of parent needs to become the height of the flowPane."* Why don't you just wrap the flowpane in a `Group`? – James_D Feb 28 '23 at 19:27
  • Thank you for informing me that Group accounts for the transformation of its child regions. Wrapping it in Group is exactly what I need to do. – Jody Sowald Feb 28 '23 at 19:42

0 Answers0