.NET MAUI: Unwanted whitespace at bottom of screen using grid layout - ios

I have a simple grid layout:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="5*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Button Grid.Row="0"
Text="Test1"
VerticalOptions="Fill"
BackgroundColor="Green"/>
<Button Grid.Row="1"
Text="Test2"
VerticalOptions="Fill"
BackgroundColor="Red"/>
</Grid>
I expect the red area to extend all the way to the bottom of the screen. However, There's some white space.
If I change it to a collection view with a footer, it properly fills the bottom section of the screen:
For reference:
<CollectionView>
<CollectionView.Header>
<Button
Text="Test1"
VerticalOptions="Fill"
BackgroundColor="Green"/>
</CollectionView.Header>
<CollectionView.EmptyView>
<Label Text="No items"/>
</CollectionView.EmptyView>
<CollectionView.Footer>
<Button
Text="Test2"
VerticalOptions="Fill"
BackgroundColor="Red"/>
</CollectionView.Footer>
</CollectionView>
Is there a correct way to fill that bottom "footer" area on a grid view? or without using a collection view?
I don't think it matters but I'm running in iOS simulator on Mac iOS 16.2.

The white space at the bottom of the screen is iOS Page UseSafeArea in iOS. However, it is not yet implemented in Maui and you can track the MAUI issue here: https://github.com/dotnet/maui/issues/5856.
As an alternative workaround for now, you can set the Page Padding value to remove the bottom white space. In the OnAppearing Method, set the safeInsets of the page:
protected override void OnAppearing()
{
base.OnAppearing();
DeviceSafeInsetsService d = new DeviceSafeInsetsService();
double topArea = d.GetSafeAreaTop();
double bottomArea = d.GetSafeAreaBottom();
var safeInsets = On<iOS>().SafeAreaInsets();
safeInsets.Top = -topArea;
safeInsets.Bottom = -bottomArea;
Padding = safeInsets;
}
And then write platform specific code to get the topArea and bottomArea value.
1.Create DeviceSafeInsetsService.cs in Project folder.
public partial class DeviceSafeInsetsService
{
public partial double GetSafeAreaTop();
public partial double GetSafeAreaBottom();
}
2.And then under the Project/Platform/iOS folder, create a iOS specific class DeviceSafeInsetsService.cs:
public partial class DeviceSafeInsetsService
{
public partial double GetSafeAreaBottom()
{
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow();
var bottomPadding = window.SafeAreaInsets.Bottom;
return bottomPadding;
}
return 0;
}
public partial double GetSafeAreaTop()
{
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow();
var TopPadding = window.SafeAreaInsets.Top;
return TopPadding;
}
return 0;
}
}
For more details, you can refer to this sample .NET MAUI Platform Code Sample.

Set your Corner Radius property to 0 in your button control's property definition
<Button
CornerRadius="0"
Text="Test2"
VerticalOptions="Fill"
BackgroundColor="Red"/>

Related

How to get Button Coordinates for button in iOS Xamarin form

I have created below render to get the Coordinates.
I am getting X coordinates value, but Y coordinates value is always 0.
public class ContextMenuButtonRenderer : ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (Element is ContextMenuButton contextButton)
{
contextButton.GetCoordinates = GetCoordinatesNative;
}
}
private (int x, int y) GetCoordinatesNative()
{
return ((int)Frame.Left, (int)Frame.Top);
}
}
How to get Y coordinate value ?
There is a relatively simple method in Xamarin.Froms. AbsoluteLayout can specify the position and child level. You can determine the coordinate position of the button when adding it, like this:
<StackLayout >        
<Label Text="Welcome to Xamarin.Forms!" HorizontalTextAlignment="Center" />      
                
<AbsoluteLayout>            
<Button Text="111"  AbsoluteLayout.LayoutBounds="80,100,50,20"/>           
<Button Text="222" AbsoluteLayout.LayoutBounds="180,100,50,20"/>        
</AbsoluteLayout>    
</StackLayout>
For more details, you can refer to the document: Xamarin.Forms AbsoluteLayout
Update:Touch Effects in Xamarin.Forms can get the touch coordinates, I tested the official sample can be obtained normally. You can refer to TouchTrackingEffect Code, the FireEvent event in the TouchRecognizer class in the iOS part of the sample to convert the touch position into a point value. For more details about Touch Effects, you can check the official document: Invoking Events from Effects

Resize WebView defined in Xamarin.Forms Core library on screen rotate event

I have web page defined in the core library as view to fill whole screen:
Content = new WebView
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Source = "https://google.com",
};
Unfortunately on screen rotate it's not resized (please see below):
How can I make sure that screen is resized on screen rotation.
If it's iOS, then make a custom WebView renderer (http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/):
protected override void OnElementChanged (VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
ScalesPageToFit = true;
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
NativeView.Bounds = UIKit.UIScreen.MainScreen.Bounds;
}
Please try this solution, it works in iOS 8.4, but not iOS 7.
Xamarin Forms: How to resize the Webview after rotation in iOS
You need to be working with webview using Xamarin.forms.
Working with WebView in Xamarin.Forms
xamarin-forms-samples/WorkingWithWebview Has examples for each platform.
This link on Handling Rotation gives you all the details you need for android. The other answer has covered iOS.
Responding To Orientation Changes In Xamarin Forms another great link
Customizing Controls for Each Platform using these premise you can manage the screen rotation for each platform separately within the one app.
Handling Runtime Changes shows how to manage screen rotation. You need to scroll down the page.
A good link on managing windows phone, The two ways to handle orientation in your Windows 8.1 app.
Another useful link Fix IE 10 on Windows Phone 8 Viewport.
This is an interesting link on Managing screen orientation from mozilla. It is experimental, but interesting.
I implemented the custom renderer and added the line "webView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;" but it doesn't work for me. Then, I solved this with a not so elegant solution (reloading the WebView component when the device orientation changes).
In my xaml:
<StackLayout Padding="0" >
<WebView x:Name="viewJupyter" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" />
</StackLayout>
And my code behind class:
public partial class ServiceChart : ContentPage
{
private int _rotateView;
public ServiceChart(string title, string url)
{
Title = title;
InitializeComponent();
var urlPage = new UrlWebViewSource
{
Url = url
};
viewJupyter.Source = urlPage;
if (Device.OS == TargetPlatform.iOS)
{
SizeChanged += (sender, arg) =>
{
if (_rotateView != 0)
{
var lalala = viewJupyter;
InitializeComponent();
viewJupyter.Source = (lalala.Source as UrlWebViewSource).Url;
}
_rotateView++;
};
}
}
}

How to Change the MenuItem Colors of Forms ViewList in iOS ViewCellRenderer?

Is there any way to Change the color of ContextAction Menus added in Xamarin.Forms Xaml file. IsDestructive="True" sets the menu color to Red. But i need another menu to look like Green or some other color.
Here is my Forms Xaml code..
<ListView x:Name="planList" ItemsSource="{x:Static local:SampleData.PLAN_DATA}" RowHeight="150" HorizontalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="OnEditClick" Text="Edit" CommandParameter="{Binding .}"/> <!-- THIS HAS TO BE GREEN COLOR -->
<MenuItem Clicked="OnDeleteClick" Text="Delete" IsDestructive="True" />
</ViewCell.ContextActions>
<ViewCell.View>
<StackLayout Orientation="Vertical" HorizontalOptions="Start" VerticalOptions="FillAndExpand">
<!--Non Editable State-->
<StackLayout Orientation="Horizontal" Spacing="28" IsVisible="{Binding isNotSaveState}">
<Frame WidthRequest="130" HeightRequest="50" BackgroundColor="#151617" HorizontalOptions="Start">
<Label Text="{Binding from}" TextColor="#ff9600" FontSize="Medium" FontFamily="Helvetica"/>
</Frame>
</StackLayout>
<!--Editable State-->
<StackLayout Orientation="Horizontal" Spacing="0" IsVisible="{Binding isSaveState}">
<StackLayout Orientation="Horizontal" Spacing="5">
<Label Text="From" TextColor="#838288" FontSize="Medium" FontFamily="Helvetica"/>
<Entry Text="" BackgroundColor="Red"/>
</StackLayout>
<Button Text="Save" BackgroundColor="Green" CommandParameter="{Binding .}" Clicked="onSaveClick" />
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Here is my Renderer..
[assembly: ExportRenderer(typeof(MyApp.Views.Cells.CustomViewCell), typeof(MyApp.iOS.Views.Cells.CustomViewCellRenderer))]
namespace MyApp.iOS.Views.Cells
{
public class CustomViewCellRenderer : ViewCellRenderer
{
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
UITableViewCell cell = base.GetCell(item, reusableCell, tv);
// I have no Idea how to access the Swipe Menus from Renderer
//cell.EditingAccessory
//cell.EditingAccessoryView
return cell;
}
}
}
Xamarin implements the context menu by a native cell ContextActionsCell subclassing the UITableViewCell.
However, as of today Xamarin.Forms.Platform.iOS (1.4.0.6340-pre2) assembly, the ContextActionsCell that setups the gesture and buttons is still an internal class, which is not accessible or inheritable for changing anything.
BUT WAIT!
Still, you may use Reflection to change above internal stuff.
Example:
// Get UIImage with a green color fill
CGRect rect = new CGRect (0, 0, 1, 1);
CGSize size = rect.Size;
UIGraphics.BeginImageContext (size);
CGContext currentContext = UIGraphics.GetCurrentContext ();
currentContext.SetFillColor (0, 1, 0, 1);
currentContext.FillRect (rect);
var backgroundImage = UIGraphics.GetImageFromCurrentImageContext ();
currentContext.Dispose ();
// This is the assembly full name which may vary by the Xamarin.Forms version installed.
// NullReferenceException is raised if the full name is not correct.
var t = Type.GetType("Xamarin.Forms.Platform.iOS.ContextActionsCell, Xamarin.Forms.Platform.iOS, Version=1.3.1.0, Culture=neutral, PublicKeyToken=null");
// Now change the static field value!
var field = t.GetField ("destructiveBackground", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
field.SetValue (null, backgroundImage);
Note 1: This will change the destructive background colors of all context menu.
Note 2: If you also want to change the normal color, the field name is normalBackground.
Note 3: Xamarin may make these classes internal with a purpose that the API and behaviours may change in the future. Above example may break in coming releases.
For Xamarin.Forms.2.3.3.193 & Xamarin.Forms.Platform.iOS (2.x) version number Version=2.0.0.0 and field names Case changed to NormalBackground & DestructiveBackground
using System;
using CoreGraphics;
using Foundation;
using UIKit;
using Xamarin.Forms.Platform.iOS;
using Xamarin.Forms;
using System.Reflection;
[assembly: ExportRenderer(typeof(ViewCell), typeof(App.Renderers.CustomViewCellRenderer))]
namespace App.Renderers
{
public class CustomViewCellRenderer : ViewCellRenderer
{
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
UITableViewCell cell = base.GetCell(item, reusableCell, tv);
try
{
// This is the assembly full name which may vary by the Xamarin.Forms version installed.
// NullReferenceException is raised if the full name is not correct.
var globalContextViewCell = Type.GetType("Xamarin.Forms.Platform.iOS.ContextActionsCell, Xamarin.Forms.Platform.iOS, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null");
// Now change the static field value! "NormalBackground" OR "DestructiveBackground"
if(globalContextViewCell != null)
{
var normalButton = globalContextViewCell.GetField("NormalBackground", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
if (normalButton != null)
{
normalButton.SetValue(null, getImageBasedOnColor("ff9500"));
}
var destructiveButton = globalContextViewCell.GetField("DestructiveBackground", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
if (destructiveButton != null)
{
destructiveButton.SetValue(null, getImageBasedOnColor("B3B3B3"));
}
}
}
catch (Exception e)
{
Console.WriteLine("Error in setting background color of Menu Item : " + e.ToString());
}
return cell;
}
private UIImage getImageBasedOnColor(string colorCode)
{
// Get UIImage with a green color fill
CGRect rect = new CGRect(0, 0, 1, 1);
CGSize size = rect.Size;
UIGraphics.BeginImageContext(size);
CGContext currentContext = UIGraphics.GetCurrentContext();
currentContext.SetFillColor(Color.FromHex(colorCode).ToCGColor());
currentContext.FillRect(rect);
var backgroundImage = UIGraphics.GetImageFromCurrentImageContext();
currentContext.Dispose();
return backgroundImage;
}
}
}

Matching the vertical scroll position of a Grid to a RichEditBox or TextBox

I've got a Windows Store app with a RichEditBox (editor) and a Grid (MarginNotes).
I need the vertical scroll position of the two elements to be matched at all times. The purpose of this is to allow the user to add notes in the margin of the document.
I've already figured out Note positioning based on the cursor position - when a note is added, a text selection is made of everything up to the cursor. that selection is then added to a second, invisible RichEditBox, inside a StackPanel. I then get the ActualHeight of this control which gives me the position of the note in the grid.
My issue is that when I scroll the RichEditBox up and down, the Grid does not scroll accordingly.
First Technique
I tried putting them both inside a ScrollViewer, and disabling scrolling on the RichEditBox
<ScrollViewer x:Name="EditorScroller"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="{Binding *" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<Grid x:Name="MarginNotes" Grid.Column="0" HorizontalAlignment="Right"
Height="{Binding ActualHeight, ElementName=editor}">
</Grid>
<StackPanel Grid.Column="1">
<RichEditBox x:Name="margin_helper" Opacity="0" Height="Auto"></RichEditBox>
</StackPanel>
<RichEditBox x:Name="editor" Grid.Column="1" Height="Auto"
ScrollViewer.VerticalScrollBarVisibility="Hidden" />
</Grid>
</ScrollViewer>
When I scroll to the bottom of the RichEditBox control, and hit enter a few times, the cursor drops out of sight. The ScrollViewer doesn't scroll automatically with the cursor.
I tried adding C# code which would check the position of the cursor, compare it to the VerticalOffset and height of the editor, and then adjust the scroll accordingly. This worked, but was incredibly slow. Initially I had it on the KeyUp event which brought the app to a standstill when I typed a sentence. Afterwards I put it on a 5 second timer, but this still slowed down the app performance and also meant that there could be a 5 second delay between the cursor dropping out of sight and the RichEditBox scrolling.
Second Technique
I also tried putting just MarginNotes in its own ScrollViewer, and programmatically setting the VerticalOffset based off my RichEditBoxs ViewChanged event.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="{Binding *" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<ScrollViewer x:Name="MarginScroller" Grid.Column="0"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid x:Name="MarginNotes" HorizontalAlignment="Right"
Height="{Binding ActualHeight, ElementName=editor}">
</Grid>
</ScrollViewer>
<StackPanel Grid.Column="1">
<RichEditBox x:Name="margin_helper" Opacity="0" Height="Auto"></RichEditBox>
</StackPanel>
<RichEditBox x:Name="editor" Grid.Column="1" Height="Auto"
Loaded="editor_loaded" SizeChanged="editor_SizeChanged" />
</Grid>
relevant event handlers
void editor_Loaded(object sender, RoutedEventArgs e)
{
// setting this in the OnNavigatedTo causes a crash, has to be set here.
// this uses WinRTXAMLToolkit as suggested by Nate Diamond to find the
// ScrollViewer and add the event handler
editor.GetFirstDescendantOfType<ScrollViewer>().ViewChanged += editor_ViewChanged;
}
private void editor_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
// when the RichEditBox scrolls, scroll the MarginScroller the same amount
double editor_vertical_offset = ((ScrollViewer)sender).VerticalOffset;
MarginScroller.ChangeView(0, editor_vertical_offset, 1);
}
private void editor_SizeChanged(object sender, SizeChangedEventArgs e)
{
// when the RichEditBox size changes, change the size of MarginNotes to match
string text = "";
editor.Document.GetText(TextGetOptions.None, out text);
margin_helper.Document.SetText(TextSetOptions.None, text);
MarginNotes.Height = margin_helper.ActualHeight;
}
This worked, but was quite laggy as scrolling is not applied until the ViewChanged event fires, after scrolling has stopped. I tried using the ViewChanging event, but it does not fire at all for some reason. Additionally, the Grid was sometimes mis-positioned after a fast scroll.
So, what makes this difficult is that the size of the text or the placement of the text in different types of TextBoxes means that syncing the scrollbar doesn't guarantee you are syncing the text. Having said that, here's how you do it.
void MainPage_Loaded(object sender, RoutedEventArgs args)
{
MyRichEditBox.Document.SetText(Windows.UI.Text.TextSetOptions.None, MyTextBox.Text);
var textboxScroll = Children(MyTextBox).First(x => x is ScrollViewer) as ScrollViewer;
textboxScroll.ViewChanged += (s, e) => Sync(MyTextBox, MyRichEditBox);
}
public void Sync(TextBox textbox, RichEditBox richbox)
{
var textboxScroll = Children(textbox).First(x => x is ScrollViewer) as ScrollViewer;
var richboxScroll = Children(richbox).First(x => x is ScrollViewer) as ScrollViewer;
richboxScroll.ChangeView(null, textboxScroll.VerticalOffset, null);
}
public static IEnumerable<FrameworkElement> Children(FrameworkElement element)
{
Func<DependencyObject, List<FrameworkElement>> recurseChildren = null;
recurseChildren = (parent) =>
{
var list = new List<FrameworkElement>();
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
if (child is FrameworkElement)
list.Add(child as FrameworkElement);
list.AddRange(recurseChildren(child));
}
return list;
};
var children = recurseChildren(element);
return children;
}
Deciding when to invoke the sync is tricky. Maybe on PointerReleased, PointerExit, LostFocus, KeyUp - there are a lot of ways to scroll is the real issue there. You might need to handle all of those. But, it is what it is. At least you can.
Best of luck.

Dynamic/instant resize in JavaFX

How do you create a JavaFX application that (instantly) dynamically resizes? Right now I have coded a simple application that dynamically resizes but the layout changes don't display until after the release of the mouse button on a drag. I want instantly see the results/layout changes before this button release.
I'm assuming this is done by just binding the correct values/controls with inverse... Any help would be great!
EDIT:
Here's how I got things working (thanks to Praeus). Exactly as he said, I had to bind my top level container/layout width and height to scene.width and scene.height. --
var scene: Scene;
Stage {
title: "Application title"
scene: scene = Scene {
content: [
XMigLayout {
width: bind scene.width;
height: bind scene.height;
...}]}}
Bind is different in JavaFX's 2.0 release. Angela Caicedo's video demonstrates how to bind properties nicely. A variable must be setup as an ObservableNumberValue and its get and set methods used. After it's setup you can then bind it to a component's property.
DoubleProperty x = new SimpleDoubleProperty(0);
x.set(1);
x.getValue();
imageView.xProperty().bind(x);
anchorPane.heightProperty().add(x);
Eric Bruno's post is another way of doing it.
scene.widthProperty().addListener(
new ChangeListener() {
public void changed(ObservableValue observable,
Object oldValue, Object newValue) {
Double width = (Double)newValue;
tbl.setPrefWidth(width);
}
});
scene.heightProperty().addListener(
new ChangeListener() {
public void changed(ObservableValue observable,
Object oldValue, Object newValue) {
Double height = (Double)newValue;
tbl.setPrefHeight(height);
}
});
Edits: Added another, more fitting answer along with where I found it.
Actually if you've already organized everything into layouts, then you might be able to just bind the top level layout container(s) width and height to the scene.width and scene.height. I don't think top level layout controls are managed by anything, so you may be safe just setting width and height of the layout control directly. If that doesn't work then you might have success binding the layoutInfo width and height.
Ideally you want to use layout management before resorting to binds. Excessive binds can be a performance problem, and can lead to slow redraws as you are resizing. In this case you can probably just use binds for the top level container, and then all of the children of the top level container should resize accordingly. At least I think that should work.
Yes I think you're on the right lines - binding would be the obvious way to do what you trying to do. You could also look at triggers.
Read the 1.3 guide to layouts as a starting point if you haven't already
The layout containers automatically manage the dynamic layout behavior of their content nodes. However, it is often desirable to also use the binding mechanism of the JavaFX Script to establish certain dynamic aspects of layout. For example, you can bind the width and height of an HBox container to the Scene height and width so that whenever Scene resizes, the HBox container resizes as well.
It's also probably worth reading articles and blog posts by JavaFX layout guru Amy Fowler
Here's what I ended up doing to get my resizing how I liked. There has to be an easier way but I surely don't know it.
My main method loads my controller and scene then calls my controllers init() method
FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml"));
Parent root = (Parent) loader.load();
primaryStage.setTitle("Robot Interface");
primaryStage.setScene(new Scene(root));
primaryStage.show();
Controller controller = (Controller)loader.getController();
controller.init();
I am using a gridpane that dynamically resizes as the whole stage is resized by the user so it always fits. This is becaus its percentage sizing. This is done in the fxml way easier than with binding IMO.
<GridPane fx:id="gridPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<columnConstraints>
<ColumnConstraints percentWidth="50" />
<ColumnConstraints percentWidth="50" />
</columnConstraints>
<rowConstraints>
<RowConstraints percentHeight="35" />
<RowConstraints percentHeight="35" />
<RowConstraints percentHeight="35" />
</rowConstraints>
<children>
<TextArea fx:id="textArea_Console" prefHeight="200.0" prefWidth="200.0" promptText="console/reponse" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<!-- <MediaView fx:id="mediaView_Images" fitHeight="225.0" fitWidth="225.0" GridPane.halignment="LEFT" GridPane.valignment="BOTTOM" /> -->
<TextArea fx:id="textArea_RoboAvail" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="121.0" prefWidth="123.0" promptText="robots available" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.valignment="TOP" />
<TextArea fx:id="textArea_SensorData" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="249.0" prefWidth="106.0" promptText="sensor data" GridPane.halignment="RIGHT" GridPane.valignment="TOP" />
<TextArea fx:id="textArea_Scripting" prefHeight="200.0" prefWidth="200.0" promptText="Scripting" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Currently Viewing" GridPane.halignment="LEFT" GridPane.valignment="TOP" />
<TextArea maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="250.0" prefWidth="100.0" promptText="to do list" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.valignment="TOP" />
<ImageView fx:id="imageView_Images" fitHeight="233.0" fitWidth="225.0" pickOnBounds="true" preserveRatio="true" GridPane.halignment="LEFT" GridPane.valignment="TOP" />
<Label fx:id="label_CheatSheet" text="Label" GridPane.halignment="LEFT" GridPane.rowIndex="2" GridPane.valignment="BOTTOM" />
</children>
Remember how my controller class had its init() method called. Well init() calls setupUI where I get my height and width and create callbacks for height and width changes later. Those change my class wide variables mHeight and mWidth;
private void setupUI()
{
imageView_Images.setImage( new Image("file:///C:\\Users\\administration\\IdeaProjects\\Robot User Interface\\Media\\filler.jpeg"));
mHeight = gridPane.getHeight();
mWidth = gridPane.getWidth();
//for initial startup sizing
dynamicRsize();
//callbacks to detect changes for sizing
gridPane.widthProperty().addListener(new ChangeListener<Number>() {
#Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
mWidth = newValue.doubleValue();
dynamicRsize();
}
});
gridPane.heightProperty().addListener(new ChangeListener<Number>() {
#Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
mHeight = newValue.doubleValue();
dynamicRsize();
}
});
setup_TextArea_Scriptng();
setup_Label_CheatSheet();
}
Finally I can call dynamicResize() which adjust every object in the gridpane as a percentage of that rows width or height
private void dynamicRsize()
{
//two columns 50/50
//three rows 35/35/30
double columnType1 = mWidth/2;
double rowType1 = mHeight * .35;
double rowType2 = mHeight * .3;
//node 1
imageView_Images.setFitWidth(columnType1 * .75);
textArea_SensorData.setPrefWidth(columnType1 * .25);
//node 2
//node 3
//node 4
//node 5
//node 6
}

Resources