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...