Class: RSwing::Components::ComboBox

Inherits:
JComboBox
  • Object
show all
Includes:
Component
Defined in:
lib/rswing/components/combo_box.rb

Constant Summary

Constants included from Events::FocusEvents

Events::FocusEvents::FocusListener

Constants included from Events::PropertyChanged

Events::PropertyChanged::PropertyChangeListener

Constants included from Events::InputMethodEvents

Events::InputMethodEvents::InputMethodListener

Constants included from Events::HierarchyBoundsEvents

Events::HierarchyBoundsEvents::HierarchyBoundsListener

Constants included from Events::KeyEvents

Events::KeyEvents::KeyListener

Constants included from Events::MouseWheelEvents

Events::MouseWheelEvents::MouseWheelListener

Constants included from Events::MouseMotionEvents

Events::MouseMotionEvents::MouseMotionListener

Constants included from Events::MouseEvents

Events::MouseEvents::MouseListener

Constants included from Events::ComponentEvents

Events::ComponentEvents::ComponentListener

Instance Method Summary collapse

Methods included from Events::FocusEvents

event_mappings

Methods included from Events::InputMethodEvents

event_mappings

Methods included from Events::HierarchyBoundsEvents

event_mappings

Methods included from Events::KeyEvents

event_mappings

Methods included from Events::MouseMotionEvents

event_mappings

Methods included from Events::MouseEvents

event_mappings

Methods included from Events::ComponentEvents

event_mappings

Constructor Details

#initialize(items = nil, options = {}) ⇒ ComboBox

Valid items are either an array or a ComboBoxModel object. e.g.: ["First item", "Second item"] (default: nil)

Valid options are:

  1. :belongs_to => container (default: nil)

  2. :name => :text_field (default: nil)



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rswing/components/combo_box.rb', line 33

def initialize(items = nil, options = {})
  if(items.kind_of? javax.swing.ComboBoxModel)
    super(items)
  elsif(items.kind_of? Array)
    super(items.to_java(:Object))
  else
    super()
  end
  
  unless options.empty?
    Container.add_if_requested(self, options)
  end
end

Instance Method Details

#[](item_index) ⇒ Object

Returns an item at a given index. Equivalent to ComboBox#item_at



49
50
51
# File 'lib/rswing/components/combo_box.rb', line 49

def [](item_index)
  self.item_at(item_index)
end

#itemsObject

Returns the items of this ComboBox as an Array.



54
55
56
57
58
59
60
61
62
# File 'lib/rswing/components/combo_box.rb', line 54

def items
  @items = []
  
  self.item_count.times do |i|
    @items << self[i]
  end
  
  @items
end