FXML cellValueFactory for TreeTableColumn - java-8

I've been trying to build a Tree Table and define the cellValueFactories in FXML.
When I try this, I get the following error in the stack trace
Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: javafx.scene.control.TreeTableColumn$CellDataFeatures cannot be cast to javafx.scene.control.TableColumn$CellDataFeatures
The FXML is written as follows
<TreeTableView prefHeight="500.0" prefWidth="600.0" fx:id="customerContractsTable">
<columns>
<TreeTableColumn prefWidth="116.0" text="Contract Number">
<cellValueFactory>
<PropertyValueFactory property=""/>
</cellValueFactory>
</TreeTableColumn>
</columns>
</TreeTableView>
I've been trying to find any documentation references on how to do this and am coming up completely empty handed. Any documentation or help would be greatly apperciated.

Here is a sample TreeTableView in FXML.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.TreeTableView?>
<?import javafx.scene.control.TreeTableColumn?>
<?import javafx.scene.control.cell.TreeItemPropertyValueFactory?>
<TreeTableView>
<columnResizePolicy>
<TreeTableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<columns>
<TreeTableColumn text="Contract Number">
<cellValueFactory>
<TreeItemPropertyValueFactory property="contractNumber" />
</cellValueFactory>
</TreeTableColumn>
</columns>
</TreeTableView>
See RT-35233.

I think it's a bug, you should log it in the JavaFX issue tracker.
I think the bug is that the TreeTableView does not define it's own builder for defining columns in FXML, so it inherits the functionality from a TableViewBuilder which only defines columns as TableColumns, not TreeTableColumns. This means that TableColumns for straight TableViews can be defined in FXML but, TableColumns for TreeTableViews cannot.
In the meantime, define your cellValueFactories for TreeTables in code (in the initializer for your controller) rather than FXML.

I had the same problem but then checked and changed the imports.
I was building a Dynamic Tableview and had used the "Fix Imports" feature of Netbeans, however I noticed that instead of importing:
javafx.scene.control.TableColumn.CellDataFeatures;
it had imported
javafx.scene.control.TreeTableColumn.CellDataFeatures;
I corrected the import manually and the problem disappeared.

Related

Why Xamarin Forms tabbedpage throws unhandled exception when the child page is wrapped inside NavigationPage?

I have a legacy Xamarin forms app to which I am trying to add a tabbed page as the root page. This is how my tabbed page xaml looks like-
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ChildPage1="clr-namespace:sampleApp;assembly=sampleAssembly">
<NavigationPage Title="Items" IconImageSource="icon_items_tab.png">
<x:Arguments>
<ChildPage1:ItemListPage BindingContext="{Binding ItemListTabVM}" />
</x:Arguments>
</NavigationPage>
<ContentPage Title="Messages" IconImageSource="icon_messages_tab.png" />
<ContentPage Title="Search" IconImageSource="icon_search_tab.png" />
</TabbedPage>
When I run the app I am getting the below unhandled exception-
Android.Views.InflateException: Binary XML file line #1 in com.sample.xamarinapp:layout/toolbar: Binary XML file line #1 in com.sample.xamarinapp:layout/toolbar: Error inflating class <unknown>
Below is the internal exception details that I pulled from the thread-
System.Diagnostics.Debugger.Mono_UnhandledException_internal()
in System.Diagnostics.Debugger.Mono_UnhandledException_internal
in System.Diagnostics.Debugger.Mono_UnhandledException at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.Diagnostics/Debugger.cs:125,4
in Android.Runtime.DynamicMethodNameCounter.104
in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:157,13
in Java.Interop.JniEnvironment.InstanceMethods.CallObjectMethod
in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualObjectMethod
in Android.Views.LayoutInflater.Inflate at /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-29/mcw/Android.Views.LayoutInflater.cs:661,5
in Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.SetupToolbar at D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:789,5
in Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged at D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:347,6
in Xamarin.Forms.Platform.Android.VisualElementRenderer<Xamarin.Forms.NavigationPage>.SetElement at D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:241,4
in Xamarin.Forms.Platform.Android.VisualElementRenderer<Xamarin.Forms.NavigationPage>.Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement at D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:131,4
in Xamarin.Forms.Platform.Android.Platform.CreateRenderer at D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:404,4
in Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.OnCreateView at D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FragmentContainer.cs:57,5
in AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ at D:\a\1\s\generated\androidx.fragment.fragment\obj\Release\monoandroid9.0\generated\src\AndroidX.Fragment.App.Fragment.cs:1977,4
in Android.Runtime.DynamicMethodNameCounter.104
in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a
in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod
in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod
in Android.Views.View.Measure at /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-29/mcw/Android.Views.View.cs:16637,5
in Xamarin.Forms.Platform.Android.AppCompat.TabbedPageRenderer.OnLayout at D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\TabbedPageRenderer.cs:398,5
in Xamarin.Forms.Platform.Android.FormsViewGroup.n_OnLayout_ZIIII at D:\a\1\s\Xamarin.Forms.Platform.Android.FormsViewGroup\obj\Release\generated\src\Xamarin.Forms.Platform.Android.FormsViewGroup.cs:206,4
in Android.Runtime.DynamicMethodNameCounter.40
in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a
in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod
in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod
in Xamarin.Forms.Platform.Android.FormsViewGroup.MeasureAndLayout at D:\a\1\s\Xamarin.Forms.Platform.Android.FormsViewGroup\obj\Release\generated\src\Xamarin.Forms.Platform.Android.FormsViewGroup.cs:189,5
in Xamarin.Forms.Platform.Android.VisualElementTracker.UpdateLayout at D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementTracker.cs:111,5
in Xamarin.Forms.Platform.Android.VisualElementRenderer<Xamarin.Forms.TabbedPage>.UpdateLayout at D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:139,4
in Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout at D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:235,4
in Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout at D:\a\1\s\Xamarin.Forms.Platform.Android\PlatformRenderer.cs:78,4
in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-29/mcw/Android.Views.ViewGroup.cs:3612,4
in Android.Runtime.DynamicMethodNameCounter.34
If I remove the NavigationPage wrapper and just place the ItemList child page as content page, application works with out any issues. Why is it throwing an exception when child page is wrapped inside a navigation page? Thanks in advance for any help.
I am using VS 2019, XF 5.0.0.2244
At first, you need to add the reference of the page in the TabbedPage, such as:
xmlns:local="clr-namespace:TabbedPageWithNavigationPage;assembly=TabbedPageWithNavigationPage"
And then use the reference of it in the NavigationPage wrapper, such as:
<NavigationPage Title="Schedule" IconImageSource="schedule.png">
<x:Arguments>
<local:SchedulePage />
</x:Arguments>
</NavigationPage>
If you need more information, please check the official document to how to use the NavigationPage wrapper: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/tabbed-page
Alright, after spending some time, I finally resolved the issue. Here is what I did-
In the internal error information that I shared in my question, there was a mention about "Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout". So, I created a custom renderer using TabbedPageRenderer and created an override to 'OnLayout()'. When I ran the code, I got the same exception at base.OnLayout(changed, left, top, right, bottom), but this time with more information and stack trace.
The stack trace showed the Actual error -
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 37: TypedValue{t=0x2/d=0x7f030007 a=6} at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:781) at android.view.View.<init>(View.java:5522)
So, I did a search on this particular exception and this post gave me some idea.
I added a Toolbar.xml under Resource/Layout. I removed the below themes that we usually find in the Toolbar.xml.
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" android:popupTheme="#style/ThemeOverlay.AppCompat.Light"
After that, my application started working. Tabs display the navigation pages with out any issues.
By the way I used the Toolbar.xml content from here.

Xamarin.forms Stand-alone resource dictionaries don't update dynamically if there is no cs code behind file

Xamarin team introduced 2 different way of stand-alone-resource-dictionaries. Obviously there is a big difference but they neglected to write in their documentation.
Basically if i use without cs code behind file and without x:class defined as defined in the documentation and referencing like that in my page
<ResourceDictionary Source="GradientStyles.xaml"/>
GradientStyles.xaml look like below and i am updating GradientStartColor , GradientStopColor of PancakeView on runtime based on the theme selected.
<pancakeView:GradientStopCollection x:Key="BackgroundGradientStops">
<pancakeView:GradientStop Color="{StaticResource GradientStartColor}"
Offset="0"/>
<pancakeView:GradientStop Color="{StaticResource GradientStopColor}"
Offset="0.74"/>
</pancakeView:GradientStopCollection>
Implementation above just not working. It doesn't update Colors at all.
The same exact code;
Works in ContentPage.Resources directly. It will update
Works if i define a stand-alone-resource-dictionary with cs code behind file and implement on the page like this below
<ResourceDictionary.MergedDictionaries>
<resDics:GradientStyles />
</ResourceDictionary.MergedDictionaries>
There is that annotation in the documentation but i don't get what exactly it means.
This syntax doesnot instantiate the MyResourceDictionary class.
Instead, it references the XAML file.
Does it mean that it extends the contentpage using like partial class or inherits. Or is it cached only once and remains static? And when you use it with code behind class, it creates a new instance every time?
Finally is that a bug or feature? :)

Font text changes size on mouseclick in TextField javafx

I am facing a problem with javafx TextField. I created my TextField using scene builder and the following code was generated:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?>
<StackPane fx:id="placeHolder" styleClass="pane-with-border" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<HBox prefHeight="37.0" prefWidth="1203.0">
<children>
<TextArea fx:id="resultDisplay" editable="false" prefHeight="154.0" prefWidth="1224.0" styleClass="result-display">
<font>
<Font size="16.0" />
</font></TextArea>
</children>
</HBox>
</StackPane>
I am using this TextField to display results. Hence, I set it to be non-editable. However, once the results have be displayed in this TextField and I click on it, the font-size decreases (as shown below).
When I click on other components in the window, the font-size reverts back to its original size (and the cycle continues).
I have checked my code for any mouse listener events but couldn't find any. So it is not plausible that a mouse event could have caused this problem.
If there is a need to see the actual application and code, my gradle project can be
found here.
Could someone please advise me on how to resolve this issue?

Custom Attribute of Integer on Custom View

I'm having a few problems creating an integer attribute.
So, as background. I have got a custom canvas view. I have already successfully created a custom string attribute on that. The axml looks like this:
<turbineApp.droid.infrastructure.customViews.TurbineMapCanvas
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/VicMapCanvas"
custom:mapName="VIC"
/>
And the attribute comes from attrs.xml:
<resources>
<declare-styleable name="CustomCanvasView">
<attr name="mapName" format="string" />
</declare-styleable>
</resources>
I was hoping to add an integer attribute. So, I added the following as an element in attrs.xml:
<attr name="originY" format="integer" />
But now the project won't build. At all. With a fail message that the Resources class never got built.
I've unblocked myself by just making it a string and parsing the string in the code. But why will an integer not work? Have the good people at Xamarin not implemented that yet?
Thanks

palettes of icons in Google Earth (Mac)

(Cross posted from the GE support groups - now defunct?)
Having trouble using the gs:x extensions to use palettes of icons in an icon
group.
I have loaded the appropriate xmlns:gx="http://www.google.com/kml/ext/2.2"
into the kml header but get the message "Unknown type gs:x
on my Macintosh under GE Google Earth 6.0.3.2197
I suspect this has not been implemented on the Mac version - anybody
with experience on this?
Final code was as follows and it fails on the first gx:s line.
It also fails in the same way if I use the now deprecated x (rather than gx:x)
Also, as shown it follows the kml documentation but I think all terminating terms should be of the form /gx:x rather than gx:x/
as shown in the KML reference. Making that change does not help as it never gets to that point anyway.
The header was copied from a GE placemark copied and pasted into the
editor.
Any help appreciated.
Bob J.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:kml="http://www.opengis.net/kml/2.2"
xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<StyleMap id="s_Ic_SP">
<Pair><key>normal</key><styleUrl>#sn_Ic_SP</styleUrl></Pair>
<Pair><key>highlight</key><styleUrl>#sh_Ic_SP</styleUrl></Pair>
</StyleMap>
<Style id="sn_Ic_SP">
<IconStyle>
<scale>1.8</scale>
<Icon>
<href>Icons/Traps.png</href>
<gx:x>0<gx:x/><gx:y>128<gx:y/> <gx:w>64<gx:w/><gx:h>64<gx:h/>
</Icon>
<hotSpot x="32" y="1" xunits="pixels" yunits="pixels"/>
</IconStyle>
<BalloonStyle>
<displayMode>default</displayMode><bgColor>ff00d0ff</bgColor>
<text><![CDATA[<font face="Comic Sans MS" /><table
bgcolor="#ff8000" cellspacing="3" width="160">
<tr bgcolor="#ffff80"><td><b>Sponsor $[name]</b><br/><br/>$
[description]</td></tr></table>]]></text>
</BalloonStyle>
<LabelStyle>
<scale>0.9</scale><color>ff00ffff</color>
</LabelStyle>
<LineStyle><color>ff00ffff</color><width>2.0</width></LineStyle>
<ListStyle>
<ItemIcon>
<href>Icons/Traps.png</href>
<gx:x>0<gx:x/><gx:y>128<gx:y/> <gx:w>64<gx:w/><gx:h>64<gx:h/>
</ItemIcon>
</ListStyle>
</Style>
etc.
Oooops
Seems my problem was a syntax problem
The gx:x set do work correctly. However, they are not operational inside the ItemIcon group as shown in my example. In fact they are ignored in that group.
Thanks for your tolerance of my stupidity
Bob J.

Resources