5
$\begingroup$

Is it possible in Mathematica to add a GUI like the Tree GUI element in Visual Studio 2010 C# Windows Forms? I want to have the similar feel

enter image description here

$\endgroup$
3
  • 2
    $\begingroup$ Use Wolfram Workbench $\endgroup$
    – Sektor
    Nov 20, 2014 at 22:14
  • $\begingroup$ Does OpenerView do what you want? $\endgroup$
    – Verbeia
    Nov 21, 2014 at 1:17
  • $\begingroup$ No it doesn't look like what I want $\endgroup$
    – TraceKira
    Nov 22, 2014 at 16:06

1 Answer 1

5
$\begingroup$

AFAIK there is no ready to use functionality for this in Mathematica available at this time.

I see two possibilities to still get what you want: either use NETLink or JLink to write a GUI containing a treeview supplied by either .NET or e.g. Swing. That will mean your GUI will have to live in an extra window, will need some deeper understanding of the underlying non-Mathematica GUI functionality and will not run in the free CDF-Player.

If you want to stay within Mathematica, your best bet is to use a combination of OpenerView and Column as Verbeia suggested to achieve something that behaves a lot like the Windows TreeView but of course does not look exactly like one. Here is an example:

Module[{c}, Panel[{
     "Food" -> {
       "Fruits" -> {"Apple", "Peach"},
      "Vegetables" -> {"Tomato", "Eggplant"}
      },
     "Drinks" -> {
       "Softdrink" -> {"Coke"},
       "Alcoholic" -> {"Beer", "Wine"}
     }
   } //. {
    list : {__String} :> c @@ list,
    list : {__Rule} :> c @@ (OpenerView[{#1, #2}] & @@@ list)
  } /. c :> Function[Column[{##}]]
]]

of course there are a lot of other possibilities to implement that and you might want to put some more effort to improve various aspects, e.g. with wrapping it with a Pane with some scrollbars, some more obvious indentation for the leaves and some interactivity for the nodes with Button or PopupMenu. But the basic idea to combine OpenerView and Column or probably Grid probably won't change very much. When using PaneSelector instead of OpenerView you would have some more control over the visual appearance, but I doubt you can get it to look exactly like the Windows TreeView, especially the lines visualizing the tree connections would probably be very difficult to build.

$\endgroup$
3
  • $\begingroup$ The example is useless because the small lines connecting the nodes are missing and the nodes alignment is confusing also , not like in the C# window $\endgroup$
    – TraceKira
    Nov 22, 2014 at 17:22
  • $\begingroup$ @timoftebogdan I think if you search for people to help you you should show at least a minimal amount of politeness and the effort to read what these people write. I have explicitly mentioned that it does not look like the the windows treeview and that I think that it would be very much effort to make it look like that. As it does provide the basic functionality I personaly (and probably other readers) think it is far from useless. If you need it to look exactly like the windows TreeView the answer is probably as short as "not possible" (also already contained in my answer). $\endgroup$ Nov 22, 2014 at 17:30
  • $\begingroup$ I used TreePlot with Left so its on his side , and I think your example is worse than TreePlot: $\endgroup$
    – TraceKira
    Nov 22, 2014 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.