-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
combobox added. also added another example with a combobox.
- Loading branch information
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module ComboboxExample | ||
require "rubygems" | ||
require "rswing" | ||
|
||
include RSwing::Components | ||
|
||
GridBagLayout = java.awt.GridBagLayout | ||
|
||
frame = Frame.new "ComboBox example", | ||
:size => [400,200], | ||
:location => :center do |frame| | ||
|
||
frame.default_close_operation = :exit_on_close | ||
|
||
Panel.new :name => :panel, | ||
:belongs_to => frame, | ||
:layout_manager => GridBagLayout.new do |panel| | ||
|
||
combobox_items = ["Value 1", "Value 2", "Value 3"] | ||
ComboBox.new combobox_items, | ||
:belongs_to => panel, | ||
:name => :combobox | ||
|
||
Button.new "OK", | ||
:belongs_to => panel, | ||
:name => :ok_button | ||
|
||
Button.new "Cancel", | ||
:belongs_to => panel, | ||
:name => :cancel_button | ||
|
||
end | ||
|
||
frame.visible = true | ||
|
||
end | ||
|
||
# event handlers | ||
panel = frame[:panel] | ||
|
||
panel[:ok_button].on_click do | ||
selected_item = panel[:combobox].selected_item | ||
Dialog.show "Value selected: #{selected_item}", | ||
:dialog_type => :info, | ||
:title => "You have selected an item.", | ||
:belongs_to => frame | ||
end | ||
|
||
panel[:cancel_button].on_click do | ||
frame.dispose | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
############################################################################### | ||
# This file is part of RSwing. # | ||
# RSwing - Swing wrapper for JRuby # | ||
# (C) 2008 Christopher Bertels (bakkdoor@flasht.de) # | ||
# # | ||
# RSwing is free software: you can redistribute it and/or modify # | ||
# it under the terms of the GNU Lesser General Public License as published by # | ||
# the Free Software Foundation, either version 3 of the License, or # | ||
# (at your option) any later version. # | ||
# # | ||
# RSwing is distributed in the hope that it will be useful, # | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
# GNU Lesser General Public License for more details. # | ||
# # | ||
# You should have received a copy of the GNU Lesser General Public License # | ||
# along with RSwing. If not, see <http://www.gnu.org/licenses/>. # | ||
############################################################################### | ||
|
||
module RSwing | ||
module Components | ||
JComboBox = javax.swing.JComboBox | ||
|
||
class ComboBox < JComboBox | ||
include Component | ||
|
||
# Valid items are either an array or a ComboBoxModel object. | ||
# e.g.: <tt>["First item", "Second item"]</tt> (default: nil) | ||
# | ||
# Valid options are: | ||
# 1. <tt>:belongs_to => container</tt> (default: nil) | ||
# 2. <tt>:name => :text_field</tt> (default: nil) | ||
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 | ||
|
||
# Returns an item at a given index. | ||
# Equivalent to ComboBox#item_at | ||
def [](item_index) | ||
self.item_at(item_index) | ||
end | ||
|
||
# Returns the items of this ComboBox as an Array. | ||
def items | ||
@items = [] | ||
|
||
self.item_count.times do |i| | ||
@items << self[i] | ||
end | ||
|
||
@items | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters