Created
February 15, 2012 04:39
-
-
Save greghelton/1833242 to your computer and use it in GitHub Desktop.
JRuby gives me the opportunity to find which is worse, my Swing or my Ruby
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
require 'java' | |
swing_classes = %w(JFrame JButton JList JSplitPane | |
JTabbedPane JTextPane JScrollPane JEditorPane | |
DefaultListModel ListSelectionModel BoxLayout | |
JScrollPane JTree tree.TreeModel | |
text.html.HTMLEditorKit tree.DefaultMutableTreeNode tree.TreeNode) | |
swing_classes.each do |c| | |
java_import "javax.swing.#{c}" | |
end | |
def main | |
n = 0 | |
frame = JFrame.new("Disk File Info") | |
dir = Dir.new("./testdir") | |
dir_node = DefaultMutableTreeNode.new(dir) | |
tree = JTree.new(dir_node) | |
scrollPane = JScrollPane.new(tree) | |
dir.each { |f| | |
node = DefaultMutableTreeNode.new(f) | |
dir_node.insert(node, n) | |
n += 1 | |
} | |
cp = frame.getContentPane() | |
cp.add(scrollPane) | |
frame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE) | |
frame.pack() | |
frame.set_visible(true) | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment