Oddity (for me), just reporting it: NameError: no method 'add' for arguments (javax.swing.JButton,java.awt.GridBagConstraints,org.jruby.RubyProc) on Java::JavaxSwing::JPanel #8439
rubyFeedback
started this conversation in
General
Replies: 2 comments
-
These sorts of discussions may be helpful for future users, but perhaps you could open them as discussions instead? They would still be searchable but would not clog up the issues list. Thanks for your continued contributions here! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Ok that was a bit ambiguous... these discussions are useful, but should probably be GitHub Discussions opened here: https://github.com/jruby/jruby/discussions |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Today I ran into an (to me) interesting error.
The error was this:
.add() is a typical method for container-widgets in java-swing/jruby-swing - or
rather, in general. I think ruby-gtk3 also has an .add() method for most of the
container-widgets.
Now the method call I was using was using three arguments:
First argument, widget, would be for JPanel in my case.
grid_bag_constraints was my wrapper over GridBagConstraints, in the hope of
using less code.
&block was just a dump of the "primary" block being passed.
The method was similar to the following one, on class JPanel:
The faulty part is the last &block. I removed it and the method works fine now,
but ... I was wondering about it nonetheless. Granted, I handle the block
arguments within the method itself, for java.awt.GridBagConstraints, so I don't
need to pass it into the method .add(). However had, isn't the error message
kind of strange?
I believe in MRI ruby, such an error would not be raised; the second &block
within the add() call would just be ignored silently, I think. In jruby it
seems as if it is a specific instance of a class called org.jruby.RubyProc,
and this is then checked against various signature methods (I think?).
Java Swing .add() has several invocation ways:
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/JPanel.html
So I somewhat understand that jruby has to remain flexible here - I understand
that constraint. Still, it was a bit peculiar to me that this would yield
an error. Again, I can kind of understand it, but it was peculiar to see.
I am not really saying anything has to be changed, mind you, so I'll close
this issue, but it is another small oddity, so the purpose of this here is
primarily to point it out. It seems there are some slight differences between
jruby and MRI ruby and newcomers to jruby may not know all of these differences
initially (I am still finding them, probably in the future as well, I suppose).
Beta Was this translation helpful? Give feedback.
All reactions