Binding elements to SwiXML in JRuby

I am trying to recreate SwiXML examples in JRuby. But the objects
created in JRuby never seem to be visible to SwiXML. Here is an example.

The Java code from the SwiXML example is as follows:

public class ActionTest {
// Create an Action as a member variable
public Action quit = new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
System.exit(0);
}
};
public ActionTest() throws Exception {
// set the Action’s name
quit.putValue(Action.NAME, “Quit”);
// build the GUI
new SwingEngine(this).render(“ActionTest.xml”)
.setVisible(true);
}
public static void main(String[] args) throws Exception {
new ActionTest();
}
}

I have created some JRuby code to correspond to this, but it seems as if
the @quit member is never seen. Also tried referencing other named
elements (not in this example):

require ‘java’
require ‘java/swixml.jar’
require ‘java/jdom.jar’

include_class ‘javax.swing.AbstractAction’
include_class ‘javax.swing.Action’
include_class ‘javax.swing.JButton’

class MyAction < AbstractAction
def actionPerformed(ae)
exit # puts “Clicked”
end
end

class Main < Object # Java::JavaLang::Object
def initialize
@quit = MyAction.new
@quit.putValue(Action.NAME, “Quit”)
@f = java.io.File.new(“sample.xml”)
@se = org.swixml.SwingEngine.new(self).render(@f).setVisible(true)
end
end

Main.new

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs