Skip to content

Instantly share code, notes, and snippets.

@greghelton
Created February 15, 2012 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greghelton/1833242 to your computer and use it in GitHub Desktop.
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
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