Class: SwingParadise::ComboBoxExample

Inherits:
JFrame
  • Object
show all
Includes:
BaseModule
Defined in:
lib/swing_paradise/examples/003_combo_box_example.rb

Overview

SwingParadise::ComboBoxExample

Constant Summary

Constants included from SwingParadise

LAST_UDPATE, VERSION

Instance Method Summary collapse

Methods included from BaseModule

#bold_text, #checkbox, #combo_box, #commandline_arguments?, #create_boxlayout, #create_grid, #default_close, #do_quit, #empty_border, #entry, #first_argument?, #hbox, #infer_the_namespace, #is_visible, #java_colour, #jbutton, #jlabel, #jpanel, #jscroll_pane, #jtextarea, #make_bold, #namespace?, #password_field, #quit_button, #reset_the_internal_hash, #return_pwd, #right_aligned_label, #set_commandline_arguments, #text, #this_file_was_not_found, #use_jruby?, #vbox, #word_wrap

Methods included from SwingParadise

#jcombobox, #jframe, #jruby_font, #jtextview, #quit_button, remove_html, #show_message_dialog, #swing_dimension, text, #text

Constructor Details

#initialize(run_already = true) ⇒ ComboBoxExample

#

initialize

#


26
27
28
29
30
# File 'lib/swing_paradise/examples/003_combo_box_example.rb', line 26

def initialize(
    run_already = true
  )
  run if run_already
end

Instance Method Details

#runObject

#

run

#


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/swing_paradise/examples/003_combo_box_example.rb', line 35

def run
  frame = frame('A combo-box example')
  panel = jpanel # This is an instance of Java::JavaxSwing::JPanel.
  panel.set_font(Font.new('Calibri', Font::PLAIN, 30))
  frame.getContentPane.add(panel)
  panel.setLayout(nil)
  panel.hint = 'A text area example'
  array = %w( apple bird cat dog eagle ferret )
  combo_box = JComboBox.new
  array.each {|this_item|
    combo_box.addItem(this_item)
  }
  combo_box.setSelectedIndex(2)
  combo_box.set_font(Font.new 'Sans serif', Font::PLAIN, 32)
  combo_box.set_bounds(10, 20, 400, 80) # Last two are width and height.
  combo_box.add_action_listener { |event|
    case event.get_action_command
    when /comboBoxChanged/
      current_selection = combo_box.selected_item.to_s
      e 'The selected item is: '+current_selection
    end
  }
  panel << combo_box
  frame.exit_on_close
  frame.set_size(500, 400)
  frame.setLocationRelativeTo(nil)
  frame.show_all
end