I'm using the Hub control in a Windows 8.1 XAML app and I've got a Canvas control that I want to fit to the available height of its HubSection. In HTML I can just set heights to 100%, but I'm stumped on how to do it in XAML. Any clues?
In general for XAML if you want any UIElement to fill out it's parent horizontally and/or vertically you use the HorizontalAlignment and VerticalAlignment properties. By setting these two properties to stretch, the element will fill out it's parent entirely.
However, some controls determines their size based on their content (such as StackPanel). If you have say a empty Grid inside a StackPanel then the resulting size of the StackPanel is (0,0).
It can messy to figure out what is preventing your content from displaying itself as desired. The best way to figure out what is going on is to dig into the templates for the controls you are using.
In your case pertaining to the Hub/HubSection you need to tell the HubSection that the content it hosts should stretch vertically. You can then manually control the width of the element and set it's VerticalAlignment to Stretch.
<Hub>
<HubSection VerticalContentAlignment="Stretch">
<DataTemplate>
<Canvas
Background="Red"
Width="500">
</Canvas>
</DataTemplate>
</HubSection>
</Hub>
Related
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.getContentPane().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!
I have this IText object within a parent Group object.
When I select the Group and resize it horizontally (and vertically as well) the IText resizes as well which makes the text Strech and look awfull.
Now what I would like to do is have the IText center itself (keeping its aspect ratio) within the Group.
How can I do that. I tried modifying the Width and Left of the IText when the object is scaling, but that did not work.
try use latest fabricjs version ( 1.6.0.rc1 ) and instead of using fabric.IText use fabric.Textbox.
This new class has the properties you are looking for, the controls normally used for scaling are instead used for resizing the element and the text flows inside it.
I was not able to make the latest fabric.Textbox work exactly like I wanted.
Luckily, I found a way of making the fabric.ITextcenter horizontally when the parent fabric.Group is resized horizontally and also make the same fabric.IText Text grow in size based on the vertical resize. No ugly text stretch.
Here is the solution:
https://jsfiddle.net/t44wyday/46/
When use TabPane with tabs placed on sides the tabs' headers and strings rotates and has vertical orientation. Is there any way to place tabs' string horizontally when use TabPane with the right/left sided tabs?
Put string as label into graphic node. Graphic node can be rotated (there is a rotate graphic property of the tabpane)
Specifically, instead of tab.setText("Text") use tab.setGraphic(new Label("Text")), and look at TabPane.rotateGraphic property.
If you want implementation via fxml : then yes, it is possible. You need to specify attribute rotateGraphic of tabPane, if needed, and set property graphic of a tab to a new instance of label, and that is all. Mostly all you can do via java-code, you can repeat via fxml.
Talking about tabMinWidth - I think, you should look at binding expressions here :
http://docs.oracle.com/javafx/2/api/javafx/beans/binding/Bindings.html
Specifically, I think, you should be interested in max() method - you need to have max of widths of all tabs.
I have done in this way ...
Set following CSS for Tab pane in .CSS file
-fx-tab-min-width: 30px;
-fx-tab-max-width: 30px;
-fx-tab-min-height: 130px;
-fx-tab-max-height: 130px;
After that set label in Tab graphics,Set Min Width for label (Must require)
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">
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.