Non-Java Related jRuby GUI Builder

On Fri, May 3, 2013 at 8:42 PM, Farsheed B.
[email protected]wrote:

There’s a Qt binding for JRuby (hasn’t been updated in 11 months
though):

There’s also Monkeybars, which applies a modified MVC pattern to Swing:

It looks like Steve K.'s reply didn’t make it to the list. (He may
not be a subscriber.)

Steve K. [email protected] wrote:

Shoes 4 (github/shoes/shoes4) is all jruby, and people do write games in
Shoes.

I share your non-enthusiasm for Java related UI having done a fair bit
of Swing in the thankfully distant past. However, so far my initial use
of JavaFX is promising. It by far more reminds me of Apache (Adobe) Flex
than Swing / AWT.

There is also a major corp player and decent community behind it
supporting and enhancing it. They claim it uses hardware acceleration
although I have not tested that yet.

I would suggest checking it out.

Charles M.
[email protected]

Keith B. wrote:

C harles -

To be hone st, I’ve never used a GUI builder for Swing. I have no idea
what their output i s. So I don’t know of any examples. I’m a bit
suspicious of GUI builders , believing they may nurture bad habits, such
as the production of mon olithic and comp lex frames that defy reuse.

That’s entirely up to do the developer, at least in the case of the
Netbeans GUI builder. I worked on a large commercial application that
managed satellite modems, rendering a number of detailed windows and
panels. It was written in JRuby using Monkeybars. (I’m the Monkeybars
project admin, so assorted caveats apply.)

We had several custom components that were reused. For example, a
screen might show four different modems; we didn’t code a separate modem
panel for each one, nor did we create a single monolithic panel, since
the number of modems could change . Such panels were dynamically added
or removed as needed, reusing a single component class.

That’s probably an invalid pre judice based on GUI builders I used that
predated Swing, though.

Unless it’s a tr ivial UI, you’ll want to reuse panels, both to save you
work, and for look and feel consistency . S o be careful how you use
them – it’s easy to be temp ted to do an entire frame in one step, but
t here may b e cases wher e you wou ld be better off creating individual
panels by themselves, and then assembling them eithe r in code, or in
the GUI builder, if that is possible.

Monkeybars has built-in support for the reuse of, and dynamic
creation/removal of, components and (bearing in mind all my biases) is
the only JRuby GUI framework suitable for anything of more than
moderate complexity.

And while it works really well with pre-compiled classes such as you can
get from the Netbeans GUI builder you can also easily create UI items
using in-line Ruby.

In my own Monkeybars apps I use in-line code (via the Swingset-NG gem)
to create simple stuff like an “About” screen or user input forms, and a
GUI builder for anything more complicated.

You can see an example program here: https://github.com/Neurogami/JotBot

I think all the screens were made in Netbeans using the GUI tool.

To address the original post, using Monkeybars will, at some point, have
you sticking your nose into Swing. You really can’t avoid it, if only
to understand what options are available.

No matter what GUI tool you choose you will have to dig into the quirks
and foibles of the tool in order to do anything sophisticated, and that
assumes the GUI toolkit even allows for sophistication. (I.e., can you
design your own widgets outside of what the toolkit provides?)

Swing is probably not much worse than others in that regard, and offers
a tremendous range of UI options. You have to pick your battles.

James B.

Neurogami - Avant-garage Research & Development

[email protected]

I’ve actually spent a great deal of time researching this question: how
does one build a GUI app with Ruby? To answer your question here, there
are
basically two roads, in MRI (that’s Matz’s Ruby Implementation, the
non-java ruby) there are a handful of GUI libraries, all of them binding
to
one of the C/C++ toolkits: Gnome/GTK, QT, Wx, Gosu(for games) etc. The
second option is to use JRuby, and either work directly with one of the
Java toolkits (Swing, SWT, JavaFX) , or use one of the libraries that
wraps/abstacts/builds on top of those toolkits (Monkeybars, Rubeus,
Limelight, JRubyFX). Shoes has also been mentioned. It is undergoing a
rewrite that will use JRuby to provide a wrapper around SWT.

Your suggestion of using one of the MRI GUI libraries, from JRuby, would
make a lot of sense (portability of code, etc) except that all of those
libraries bind to various C libraries, and support for that in JRuby is,
well, currently unsupported. C-Ext support was offered as an experiment,
in
a previous version of JRuby (to the best of my understanding) but (again
to
the best of my understanding), it was buggy, difficult to maintain, and
essentially working against the tool. I believe it is still possible to
invoke JRuby with C-Extension support enabled, but I think for something
as
complex as a GUI toolkit, you’d have a hard time getting it working. You
could possibly bind to one of those libraries via JNI/FFI support, but
again, at this point you are basically working against the tool,
creating a
lot of trouble for yourself, to get something working which would never
really be a good fit for each other. And quite possibly you would end up
writing far, far more java code than had you just written your app using
one of those Java GUI toolkits you seem to want to avoid.

So, after all this research, what have I chosen for my projects going
forward? JRubyFX, 100%. One, JavaFX is a really nice, modern GUI
toolkit,
with a lot of manhours being poured into improving it. It uses CSS for
styling, has a great GUI builder (SceneBuilder), which produces FXML
(which
is quite readable/writable on its own), it performs well, and I could go
on
and on. It’s really easy to create your own widgets, components, etc in
JavaFX (or JRubyFX), and there’s tons of great documentation, blog
posts,
and other info easily available for it. Two, JRubyFX provides a very
ruby-ish wrapper around this, and its getting better all the time as
byteit101 has been putting a ton of work into making it a top-notch
framework. Three, efforts are currently underway to get JavaFX running
on
iOS and Android (it’s been done in Oracle’s lab, and they’ve opensourced
their proto-types). This means, it may eventually be possible to write
JRubyFX apps targeting those devices as well (This one’s a big maybe, of
course, but Android, at least, should be a very real possibility. This
stuff about the mobile stuff is just speculation on my part, nobody from
JRubyFX is doing any work on this stuff at the moment, or looking at it,
that I know of, but it’s something I am personally very intrigued by).
Four, javafx provides some really slick packaging tools for easily
building
native installers for Windows, Linux and OSX. We’ve already integrated
that
support (in basic form, with information on how to customize it
available)
into JRubyFX. Finally, Oracle themselves have stated that JavaFX is the
replacement for Swing, and that they will be phasing Swing out in favor
of
FX.

Hope that helped answer your questions, and I hope I’ve convinced you to
go
checkout JRubyFX. It’s awesome-sauce.

A great way of checking that out is via the Ensemble app which is
basically an collection of sample Java FX apps for browser style
exploration. It comes with the latest jdk i.e. as part of the samples ,
but is also available in the Apple AppStore if you are a Mac user.

Charles M.
[email protected]

Thanks for the responses, everyone.

Eric, I think I’ll check out JRubyFX.

Charles -

Just to be sure, you’re not talking about using Fx in a web browser,
right? It seems that most or all of the Java security issues have to do
with running Java in the browser.

  • Keith

Keith R. Bennett

Yes, use Glimmer (JRuby Desktop Development GUI Library). It does not rely on Swing, AWT, or any Java built-in GUI library.

It follows the Ruby way. Has a nice declarative DSL. Supports data-binding. Generates application and widget scaffolding. And, packages applications into native executables (e.g. Mac DMG file)

Let me know if you have any other questions. I’d be happy to help.