JRBuilder: Tree Demo 1
Home «  Prev    Contents    Next  » Download
JRBuilder: Tree Demo 1
A tree.
Commentary TBD         
require 'jrbuilder'

ctx = JRBuilder.new_swing_context

ctx.enter {
  attr_reader :my_frame
  # this one is just too much of a pain to type, even in our shortened form
  add_class_alias('tree_node', javax.swing.tree.DefaultMutableTreeNode)

  bgcolor = color(240,238,220)
  
  tree_nodes = 
    tree_node('Home',true) {   
      0.upto(2) do |i|
        tree_node('Foo ' + i.to_s,true) {
        0.upto(2) do |j|
          tree_node('Bar ' + i.to_s + '.' + j.to_s,true) {
          0.upto(1) do |k|
            tree_node('Baz '  + i.to_s + '.' + j.to_s + '.' + k.to_s,true)
          end
          }
        end
        }
      end
    }
  my_tree = tree(tree_nodes)

  @my_frame = frame('Tree Demo 1') { size 500, 375
    content_pane { background  bgcolor; layout :box, _parent, :Y_AXIS
      border :bevel, :RAISED }
    on_window_closing { my_frame.dispose }
    menu_bar { background bgcolor
      menu("File") {  mnemonic :VK_F; background :WHITE
        menu_item("Exit") { mnemonic :VK_X; background :WHITE
          on_click { my_frame.dispose }
        }
    } }
    panel { background bgcolor; layout :box, _parent, :Y_AXIS
      border :compound, border(:titled, 'Lame Tree Demo') {
        border :etched,:LOWERED }, border(:empty,7,7,7,7)
      scroll_pane(my_tree)
    }
  }
}

ctx.my_frame.show  
Home «  Prev    Contents    Next  » Download