Codename one - scrollable layout restrictions - layout

I have done my own version of the PropertyCross Demo (provided in their demo section).
The problem I currently face is the size of the "Recent Search" area. While I have a non-scrollable container, I can easily define the preferred height. As the Box Layout adheres to the preferred size, all is well, with the little issue of not being able to scroll it and see more than one result:
recentSearchContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS)); recentSearchContainer.setPreferredH((int)(this.getContentP‌​ane().getHeight() * 0.1f));
Once I set the container to scrollable, the preferred height gets overwritten and takes up as much space as it needs, taking too much space from the BorderLayout Center piece above it.
How to manipulate the preferred size of scrollable components?

You don't manipulate the preferred size. Scrollables take up more space so if you need them to take up a specific amount of space you need to use the right type of layout which in this case might not be border layout...
Border layout gives NORTH/SOUTH elements their preferred height which might not be what you want. You might want a grid layout which will divide the height 50/50. You might want a table layout where you can define the height in percentages etc.

For those who are interested, here is the solution:
Setup a table layout with a single column and as many rows as you need (similar to box layout y axis or border layout which only north, center and south).
Set the table layout to non-scrollable so it defaults to 100% of your screen.
add the components with height % of the screen they should take up.
those components can be scrollable and will still stick to the height constraint!
// inside a form object, setup the layout
TableLayout tl = new TableLayout(3, 1);
tl.setGrowHorizontally(true);
setScrollable(false);
setLayout(tl);
...
// and add stuff to it
add(tl.createConstraint().heightPercentage(15), labelDesc);
add(tl.createConstraint().heightPercentage(50), compGroup);
add(tl.createConstraint().heightPercentage(35), recentSearchContainer);
Works like a charm!

Related

Create dynamic static grid layer for editable gridstack grid

I am trying to create dashboard edit mode grid with gridstack javscript library.
Here is what I am trying to accomplish which is similar to this Databox platform. This is what it looks like when you edit any of the dashboard to view/edit it in grid mode.
So when I drag the blue border handle and scale the div(or even move with cursor hand) then the around grid(which is background layer with absolute position in reality) is automatically adjusted to match the corresponding div. Like this.
Even if there are multiple widgets there, resizing is working everything perfectly fine.
e.g. if there was any sibling widget then resizing this widget would also resize the sibling widget but can not go beyong 1 * 1 grid which is smallest size there.
Even after resizing both widgets, the background static grid boxes (with yellow border) fills the remaining vacant space similar to what is the concept of dense packing algorithm in css grid.
They are removed when widget is grown and added when it is shrinked.
As it seems super complicated to achieve this, is there any default feature like this with grid-stack library?

How to prevent west and East elements from overlapping center in BorderLayout

I'm trying to create a layout in this sketch
I want to have a vertical slider in the center, one SpanLabel on the left and another on the right.
I've tried using BorderLayout, but the SpanLabels overlap the slider if their texts are long. Is there a Layout that I could use to achieve a similar style or something I could do to fix BorderLayout?
CenterAbsolute and CenterCenter don't help in fixing this.
I'd use a TableLayout with percentages for each column to achieve this sort of layout.
BorderLayout assumes the preferred size of the elements on the sides/top/bottom isn't too big to cover everything so it's a bit problematic in some use cases.

Why won't the children in my JavaFX HBox grow (SceneBuilder)?

The JavaFX docs for HBox say:
If an hbox is resized larger than its preferred width, by default it will keep children to their preferred widths, leaving the extra space unused. If an application wishes to have one or more children be allocated that extra space it may optionally set an hgrow constraint on the child. See "Optional Layout Constraints" for details.
In the attached image, why isn't the button filling the horizontal width?
Isn't that the same as the HBox.setHgrow(field, Priority.ALWAYS) code the docs refer to.
Select your button as you have done in your screenshot and in those Size boxes in the Layout pane on the right set the Max Width to:
MAX_VALUE
This will stop the maximum size of the button from being bound to the preferred size of the button.
See Oracle's Tips for Sizing and Aligning Nodes
UI controls also provide default minimum and maximum sizes that are based on the typical usage of the control. For example, the maximum size of a Button object defaults to its preferred size because you don't usually want buttons to grow arbitrarily large.
....
To enable all of the buttons to be resized to the width of the VBox pane, the maximum width of each button is set to the Double.MAX_VALUE constant, which enables a control to grow without limit. An alternative to using the maximum value constant is to set the maximum width to a specific value, such as 80.0.
If you use fxml directly, you can use the maxWidth="Infinity", or - just as SceneBuilder does when using MAX_VALUE that is represented by maxWidth="1.7976931348623157E308".
This could look like this (the progress bar is inside a GridPane:
<ProgressBar maxWidth="Infinity" prefWidth="200.0" progress="0.0" GridPane.columnIndex="0" GridPane.hgrow="ALWAYS" GridPane.rowIndex="2" GridPane.valignment="CENTER">

ScrollPane with preferedViewportWidth matching preferedWidth of content

I have a bunch of regions which have a specific preferedWidth set. These Regions are reused visual components in a drag and drop UI.
I want to create a conatainer of these regions and tried to accomplish this with a ScrollPane with an embedded VBox. I want the scrollpane to be wide enough to hold the VBox without horizontal scrolling.
I could figure out the width of the VBox by hand and hardcode the scrollbars width but i would prefere a dynamic solution so that i can style the vbox later. Unfortunately the vbox preferred width is -1 even though its children have a prefered width set.
Also if i try to set the scrollpanes preferedViewportWidth to the width of my regions i get mixed results dependent on the hbarPolicy. If the policy is set to AS_NEEDED the width of the scrollbar is ignored and the scrollbar appears over my regions when it appears.
Any ideas how i get a SrollPane which is wide enough for my regions with and without a vertical scrollbar and possible styling of paddings etc.
Solved my problem by binding the ScrollPane's prefViewportWidthProperty() to the width property of the child.

Even distribution of views in a layout

Is there any way, I can add UI components (Buttons in my case) to any layout (RelativLayout in my case) and width of parent gets evenly distributed among all views.
say parent width = 100;
if I add 10 Buttons - all buttons should be of width 10.
thanks.
m
If you use a LinearLayout you can make use of layout_weight to evenly distribute the size.
For eg, if you have two buttons, to take half width each of its parent, you can give "layout_weight=1" in both the buttons. So both of them would share the space.
Checkout the layout_weight documentation for more details

Resources