views:

316

answers:

1

Hi,

What's the proper way to set up a scroll pane using groovy's SwingBuilder? I'm using griffon and I'm having a hard time adding and removing components dynamically...

Here's a snippet I've tried within SwingPad. It works ok, but the remove only take immediate effect if my scroll pane has scrollbars. If not, it takes 4-5 secs.

Here's the snippet:

import java.awt.Dimension

panel(id:'main') {
   panel {   
    button(name:'x', action: action(name:'add', closure:{p.add(label('new')); main.revalidate()}))
    button(action: action(name:'remove', closure:{p.removeAll();main.revalidate()}))
  }

    panel() {
      scrollPane(preferredSize: [200,200], constraints: context.CENTER) {
        panel(id:'p') {
          checkBoxList(listData: (1..20).collect([]){"Option $it"} as Object[])

      }
    }
  }
}
+2  A: 

Looks like it's a repaint issue, as this seems to work:

  panel(id:'main') {
    panel {   
      button(name:'x', action: action(name:'add', closure:{p.add(label('new')); p.revalidate()}))
      button(action: action(name:'remove', closure:{p.removeAll();p.revalidate();scroll.repaint()}))
    }

    panel() {
      scrollPane(id:'scroll',preferredSize: [200,200], constraints: context.CENTER) {
        panel(id:'p') {
          checkBoxList(listData: (1..20).collect([]){"Option $it"} as Object[])
        }
      }
    }
  }
tim_yates