The code in example.rb would result in an JFrame looking like this:
Code:
require 'springlayout_dsl' require 'java' java_import javax.swing.JFrame java_import javax.swing.JLabel java_import javax.swing.JButton java_import javax.swing.SpringLayout java_import javax.swing.Spring java_import java.awt.Color java_import javax.swing.JTextField java_import java.util.HashMap frame = JFrame.new 'Test Frame' frame.default_close_operation=JFrame::EXIT_ON_CLOSE content = frame.content_pane layout = SpringLayout.new content.layout = layout label1 = JLabel.new(" foo") label2 = JLabel.new(" bar") label3 = JLabel.new(" some long text") text1 = JTextField.new() text2 = JTextField.new() text3 = JTextField.new() [label1,label2,label3,text1,text2,text3].each {|component| content.add(component)} SpringLayoutDSL::layout(layout) do label1.north = content.north + 5 label2.north = label1.south + 5 label3.north = label2.south + 5 m = 5 + max(label1.width,label2.width,label3.width) label1.east = m label2.east = m label3.east = m content.south = label3.south + 7 content.east = 300 text1.north = label1.north text1.east = content.east - 5 text1.west = label1.east + 5 text2.north = label2.north text2.east = content.east - 5 text2.west = label2.east +5 text3.north = label3.north text3.east = content.east - 5 text3.west = label3.east + 5 end frame.pack frame.visible=true
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright © 2010 Roman. See LICENSE for details.