JRuby and Swing - Runs OK, IDE Errors

I'm using IntelliJ with the Ruby plugin.  JRuby runtime.  The following code runs in JRuby without errors, but the IDE says there are errors in the code (at JOptionPane.showMessageDialog and d.add b).  It seems like a bug in the IDE intellisense / linter.

require 'java'
import 'java.awt.GridLayout'
import 'javax.swing.JButton'
import 'javax.swing.JOptionPane'
import 'javax.swing.JDialog'
import 'java.awt.event.ActionListener'

def msg_box(msg)
  JOptionPane.showMessageDialog(nil, msg, 'a message', JOptionPane::INFORMATION_MESSAGE)
end

class ClickAction
  include ActionListener
  def actionPerformed(e)
    text = e.getSource().getText()
    e.getSource().getTopLevelAncestor().dispose()
    if text == 'A'
      msg_box('You clicked A')
    elsif text == 'B'
      msg_box('You clicked B')
    else
      msg_box('Cancel')
    end
  end
end

d = JDialog.new
d.set_bounds 300, 300, 300, 400
d.modal = true
d.set_layout GridLayout.new(8, 1, 40, 20)
d.set_title "Swing Demo"
d.set_location_relative_to nil

b = JButton.new 'A'
d.add b
b.add_action_listener ClickAction.new

b = JButton.new 'B'
d.add b
b.add_action_listener ClickAction.new

b = JButton.new('Cancel')
d.add b
b.add_action_listener ClickAction.new

d.set_visible true
1 comment
Comment actions Permalink

Hi,

it looksl ike a bug for me.  Please file it in our tracker http://youtrack.jetbrains.com/issues/RUBY

Thanks, Oleg.

0

Please sign in to leave a comment.