Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES

Documentation  / Solutions  / GUIKit  / Advanced Topics  /

Resolving Arbitrary Objects

Even though the GUIKit widget expression was designed with user interface issues in mind, we can construct object trees unrelated to user interface widgets and still take advantage of scripting with Mathematica code and setting and getting state through the use of properties.

GUIResolve allows you to resolve definitions into their runtime Java objects, but not expose a GUIObject runtime system or hold on to internal context state. This is useful if the object definition simply resolves to a set of Java objects, which you can then use in other ways through standard J/Link calls.

In[1]:=

Notice in this example, a simple Java collections object is the root object in the expression though Mathematica script code is involved in populating the container with data.

In[2]:=
myList = GUIResolve[
Widget["class:java.util.ArrayList", {
InvokeMethod["addAll",
InvokeMethod[{"class:java.util.Arrays", "asList"},
{Widget["Label", {"text" Rule "Label1"}, WidgetLayout Rule None],
"string1",
"string2",
Widget["Label", {"text" Rule "Label2"}, WidgetLayout Rule None],
Widget["class:java.util.Date"]}]
],
Script[
InvokeMethod[{"myList", "add"}, #]& /@
    {ToString[10!], 34};
]
}, Name Rule "myList"]
]

Out[2]=

Once a JavaObject is resolved by the definition, we can continue to use J/Link calls on the object instance.

In[3]:=

Out[3]=

In[4]:=

Out[4]//InputForm=
"[javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=null,border=,
flags=0,maximumSize=,minimu\

mSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,
horizontalTextPosition=TRAI\

LING,iconTextGap=4,labelFor=,text=Label1,verticalAlignment=CENTER,
verticalTextPosition=CENTER], string1, \

string2, \

javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=null,border=,
flags=0,maximumSize=,minimumS\

ize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,
horizontalTextPosition=TRAILI\

NG,iconTextGap=4,labelFor=,text=Label2,verticalAlignment=CENTER,
verticalTextPosition=CENTER], Mon Sep 01 \

23:56:28 CDT 2003, 3628800, 34]"



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information


 © 2009 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: