Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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