Class: Swing::JMenuBar

Inherits:
Object
  • Object
show all
Defined in:
lib/swing/j_menu_bar.rb

Instance Method Summary collapse

Instance Method Details

#attach_to(parent) ⇒ Object

Proper way to add menu bar to its parent



28
29
30
# File 'lib/swing/j_menu_bar.rb', line 28

def attach_to parent
  parent.setJMenuBar self if parent and parent.respond_to? :setJMenuBar
end

#post_process(opts) ⇒ Object

Override post-processing (non-setter) options given to initialize



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/swing/j_menu_bar.rb', line 6

def post_process opts
  super
  # Create menu structure from :structure opt
  structure = opts.delete :structure
  if structure
    [structure].flatten.each do |element|
      case element
        when Hash # Hash defines menu structure
          element.each do |menu_name, menu_structure|
            menu = Swing::JMenu.new menu_name.to_s, :parent => self
            menu_structure.each do |item_name, item_action|
              Swing::JMenuItem.new item_name.to_s, :parent => menu, &item_action
            end
          end
        else
          self.add element
      end
    end
  end
end