2

I am trying to display hierarchy of Groovy objects using SwingBuilder. I have spent many hours using Google to find some reasonable SwingBuilder documentation on this or some example, without success...

This is small fragment of my code:

    def builder = new SwingBuilder()
    builder.edt {
        frame(id: 'frame', title: 'Tree test', extendedState: JFrame.MAXIMIZED_BOTH, layout: new BorderLayout(), show: true, defaultCloseOperation: JFrame.EXIT_ON_CLOSE) {
            panel(border: BorderFactory.createTitledBorder(BorderFactory.createLoweredBevelBorder(), 'Tree Panel')) {
                borderLayout()
                scrollPane() {
                tree(id: 'testTree', name: 'MYROOT',rootVisible: true, showsRootHandles: true)

This produces JTree with following structure (It is strange, but I assume that some default test data are there):

JTree
   -colors
       - blue
       - violet
   -sports
   -food

After some struggle I was able to remove these nodes:

DefaultTreeModel model = (DefaultTreeModel) builder.testTree.getModel()
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot()
root.removeAllChildren()
model.reload()

But I am not able to rename root JTree node I am sure, that there must be some option in the original SwingBuilder tree command to erase these data - I can not find it....

My ultimate goal is following: - I have hierarchy of groovy objects with several elements in each object - Based on data in these objects I would like to create TreeModel (elements will be leaf nodes) - I would like to be able to be to modify data/values of leaf nodes - In the end I would like to update the TreeModel and subsequently the data in objects

Do you have/know about some really Groovy example on this? I have already found several sample codes, which are more Java than Groovy...

jirka
  • 41
  • 5
  • SwingBuilder is just poorly documented in general. I think their assumption is that you should be able to just figure everything out, but anything beyond the basic use case doesn't really work that way. Complete documentation would be awesome, but I'd generally settle for any documentation that wasn't just generated from the API. – Bill K Oct 14 '21 at 20:19

0 Answers0