You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Tiny issue] swing2.rb example at https://github.com/jruby/jruby/blob/master/samples/swing2.rb has a warning, "swing.rb:4: warning: import is deprecated; use java_import"
#7380
Closed
rubyFeedback opened this issue
Sep 24, 2022
· 3 comments
Otherwise a (harmless) warning is shown right now.
On a side note, I am currently trying to create and use an entry for
user input via jruby + swing (the JTextField) and find out how to
respond to "if user hit the enter key in the entry, call a method".
The swing2.rb kind of has a way to show how this is done via:
button.add_action_listener do |evt|
javax.swing.JOptionPane.showMessageDialog(nil, <<EOS)
<html>Hello from <b><u>JRuby</u></b>.<br>
Button '#{evt.getActionCommand()}' clicked.
EOS
But I don't know whether this will work for JTextField. Will try
to find out.
If someone feels like wanting to do extra work, it would be nice
if swing2.rb could be renamed to swing.rb or swing_example.rb
and extended with a few more widgets. Right now I am trying
to gather information from java, but the syntax is often not
easy to translate 1:1 for me for jruby+swing. In my own ruby-gtk3
code, for instance, I tend to simplify all of this via:
button.on_clicked {
}
Or:
entry.on_enter_key_pressed {
}
Not sure if jruby wants to add custom DSLs (since it is more work
I get it), but I find from a usability point of view this is so much easier
to work with. Via the add_action_listener I have to kind of simulate
the java swing API in ruby and this is not always trivial or convenient
IMO. What could help indirectly would be more examples in jruby
but these are quite hard to find. I find many more examples in java
(unsurprisingly so); for instance https://java-swing-tips.blogspot.com/
it is a really good website with TONS of code + screenshots, but it
is quite hard to translate this all back into ruby. Perhaps rubocop will
auto-correct other languages into java too one day ... :D Anyway, this
issue request is mostly about the typo, but if someone wants to improve
on swing2.rb and/or rename, that may also be nice - just as a demo
in one file. (I get that it was last modified some ~14 years ago or so...)
The text was updated successfully, but these errors were encountered:
In the event someone else finds this, the swing2.rb code works fine - on enter
key pressed in the entry, the pop up described above showed up.
For anyone finding this here via google search, I will copy paste it (entry1 is
my instance of JTextField, I kind of use a DSL for GUI stuff):
entry1.add_action_listener { |evt|
javax.swing.JOptionPane.showMessageDialog(nil, <<EOF)
<html>Hello from <b><u>JRuby</u></b>.<br>
Enter key was pressed.
EOF
}
@rubyFeedback Your description of making a friendlier face on top of Swing sounds like a great idea but it also sounds more like a gem than a core feature of JRuby. We did this for JavaFX (JRubyFx) and other than us adding some advanced features for interacting with Java classes it works fine as it's own gem. Actually, probably better since it can release on its own schedule.
As @headius said though....if you open this up in a discussion perhaps you will find some kindred spirits to hash out how to make this API?
The file at:
https://github.com/jruby/jruby/blob/master/samples/swing2.rb
I believe line 4 should be changed from:
to:
Otherwise a (harmless) warning is shown right now.
On a side note, I am currently trying to create and use an entry for
user input via jruby + swing (the JTextField) and find out how to
respond to "if user hit the enter key in the entry, call a method".
The swing2.rb kind of has a way to show how this is done via:
But I don't know whether this will work for JTextField. Will try
to find out.
If someone feels like wanting to do extra work, it would be nice
if swing2.rb could be renamed to swing.rb or swing_example.rb
and extended with a few more widgets. Right now I am trying
to gather information from java, but the syntax is often not
easy to translate 1:1 for me for jruby+swing. In my own ruby-gtk3
code, for instance, I tend to simplify all of this via:
Or:
Not sure if jruby wants to add custom DSLs (since it is more work
I get it), but I find from a usability point of view this is so much easier
to work with. Via the add_action_listener I have to kind of simulate
the java swing API in ruby and this is not always trivial or convenient
IMO. What could help indirectly would be more examples in jruby
but these are quite hard to find. I find many more examples in java
(unsurprisingly so); for instance https://java-swing-tips.blogspot.com/
it is a really good website with TONS of code + screenshots, but it
is quite hard to translate this all back into ruby. Perhaps rubocop will
auto-correct other languages into java too one day ... :D Anyway, this
issue request is mostly about the typo, but if someone wants to improve
on swing2.rb and/or rename, that may also be nice - just as a demo
in one file. (I get that it was last modified some ~14 years ago or so...)
The text was updated successfully, but these errors were encountered: