### Java Enum Values Access

To access the values of a Java Enum, make use of a JavaObject (requires the JavaObject library).
Enum Priority
Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/layout/Priority.html
Use the enum constants ALWAYS, NEVER SOMETIMES
' Access the enum
Dim joPriority As JavaObject
joPriority.InitializeStatic("javafx.scene.layout.Priority")
' Get a field value
joPriority.GetField("ALWAYS")
' or use
joPriority.RunMethod("valueOf", Array(Value))
Enum Pos
Reference: https://docs.oracle.com/javafx/2/api/javafx/geometry/Pos.html
This example populates a listview with the enum constants.
'Declare the listview
`Sub Process_Globals
Private lvwEnumConstants As ListView
...
End Sub`
'Add enum constants to the listview
`Sub AppStart (Form1 As Form, Args() As String)
...
'Populate the list with the enum constants
lvwEnumConstants.Items.AddAll(EnumPosConstants)
...
End Sub`
Build list of constants for the Enum Pos
`Sub EnumPosConstants As List
Dim result As List : result.Initialize
'Declare the JavaObject for the Java Enum Pos
Dim joJavaEnum As JavaObject
'Initialize the JavaObject as static to be able to access the enum methods
joJavaEnum.InitializeStatic("javafx.geometry.Pos")
'Get the java enum values and store in an array of objects - because the class methods values returns an array
Dim l() As Object
l = joJavaEnum.RunMethod("values", Null)
'Convert the array of objects into a string
For i = 0 To l.Length - 1
result.Add(l(i))
Next
Return result
End Sub`
Handle listview selectedindex change and log the selected value
`Sub lvwEnumConstants_SelectedIndexChanged(Index As Int)
'Get the string of the selected index
Dim enumconstant As String = lvwEnumConstants.SelectedItem
Dim joJavaEnum As JavaObject
joJavaEnum.InitializeStatic("javafx.geometry.Pos")
Log("ValueOf " & enumconstant & " = " & joJavaEnum.RunMethod("valueOf", Array(enumconstant)))
End Sub`
Example as Above but then for the Enum ContentDisplay
'#Build list of constants for the Enum ContentDisplay
`Sub EnumContentDisplayConstants As List
Dim result As List : result.Initialize
'Declare the JavaObject for the Java Enum Pos
Dim joJavaEnum As JavaObject
'Initialize the JavaObject as static to be able to access the enum methods
joJavaEnum.InitializeStatic("javafx.scene.control.ContentDisplay")
'Get the java enum values and store in an array of objects - because the class methods values returns an array
Dim l() As Object
l = joJavaEnum.RunMethod("values", Null)
'Convert the array of objects into a string
For i = 0 To l.Length - 1
result.Add(l(i))
Log(l(i))
Next
Return result
End Sub`
`Sub ButtonSetGraphic(btn As Button, Graphic As Node)
Dim jo As JavaObject = btn
jo.RunMethod("setContentDisplay", Array("CENTER"))
End Sub`

Changed: 2018-05-29 12:43, Category: Java, File: T6C205M1507.htm, ID: 1507