Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
ta.Initialize("ta")
' next line will add listener to TextArea ta and sub will be called ta_OnSelectionChanged(...)
' params 1 - Me (this class)
' 2 - The TextArea
' 3 - The prefix for OnSelectionChanged sub ie; ta
asJO(Me).RunMethod("addChangeListen",Array(Me,ta,"ta"))
MainForm.RootPane.AddNode(ta,0,0,200,200)
la.Initialize("")
MainForm.RootPane.AddNode(la,300,10,200,20)
End Sub
Sub ta_OnSelectionChanged(oldValue As String,newValue As String)
la.Text = newValue.Replace(CRLF,"<crlf>")
End Sub
Sub asJO(o As JavaObject) As JavaObject
Return o
End Sub
#if java
import javafx.scene.control.TextArea;
import javafx.beans.value.*;
import java.lang.Exception.*;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
public static void addChangeListen(final Class clss,TextArea ta,String subName) throws NoSuchMethodException,Exception{
String a="";
final Object o = clss.newInstance();
final Method m = clss.getDeclaredMethod("_"+subName+"_onselectionchanged",a.getClass(),a.getClass());
ta.selectedTextProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(final ObservableValue<? extends String> observable, final String oldValue, final String newValue) {
try{
m.invoke(o,oldValue,newValue);
} catch (IllegalAccessException iae){
System.out.println("You do not have permission to access this member");
} catch (InvocationTargetException ite){
System.out.println("Method not found in "+clss.getName());
}
}
});
}
#end if