Swing GUI Builder and Clojure

425 views
Skip to first unread message

Rock

unread,
Nov 4, 2008, 10:01:00 AM11/4/08
to Clojure
Hi all :)

Coming from CL and Scheme, I never thought I'd see the day when a
superb language like Lisp could ever stand a chance at gaining a
larger acceptance, but Clojure looks like our best bet yet. What a
fantastic job Rich! I think you've just created the Lisp of the
future :)

Anyway, where I work, I've done a lot of programming in Python on
Linux as well. I've used Glade and LibGlade extensively in this
respect, and I've come to appreciate the ease with which one can put
together a GUI application with these tools. Especially, I like the
fact that one can load the XML of the GUI in runtime and set up all
the signals to the callbacks almost automagically.

I believe it would really be cool if we had something like that, say,
with NetBeans and its GUI Builder. It would allow people to create
user interfaces without being tied to a specific language, namely
Java. And of course it would greatly benefit Clojure among other
dynamic languages.

Does anyone know of such a possibility? And, if not, what are the
chances of coming up with a tool like that? I'm not a Java nor a Swing
expert, so I haven't the faintest clue as to what the difficulties may
be.

Thanks again Rich. Keep up the excellent work :)

Chouser

unread,
Nov 4, 2008, 10:26:29 AM11/4/08
to clo...@googlegroups.com
On Tue, Nov 4, 2008 at 10:01 AM, Rock <rocco...@gmail.com> wrote:
>
> Anyway, where I work, I've done a lot of programming in Python on
> Linux as well. I've used Glade and LibGlade extensively in this
> respect, and I've come to appreciate the ease with which one can put
> together a GUI application with these tools. Especially, I like the
> fact that one can load the XML of the GUI in runtime and set up all
> the signals to the callbacks almost automagically.

One possible approach is with Qt Jambi. They have a nice GUI builder
called "designer" that generates an xml file that can be loaded at
runtime. He's a rough example:

http://paste.lisp.org/display/69450

--Chouser

Stuart Halloway

unread,
Nov 4, 2008, 10:32:50 AM11/4/08
to clo...@googlegroups.com
For the book would people rather see Swing or Qt Jambi examples? Or
something else? The book won't spend more than 10 of 250 pages on UI
stuff, so I'd rather do one reasonably interesting example than skim
several.

Stuart

Rocco Orlando Rossi

unread,
Nov 4, 2008, 10:47:40 AM11/4/08
to clo...@googlegroups.com
It depends perhaps. From what Chouser has shown us, it can be really easy to build GUIs with Qt Jambi. Maybe not as easy as with Glade and LibGlade, in that you have to hook the signals to the slots manually it seems (correct me please if I'm wrong). But still, very attractive.

There is of course Java-Gnome too. Nice architecture, and you can do all those nice things with LibGlade that I mentioned before. But it's not available (yet?) for Windows unfortunately (not that I actually care that much, but you know that OS is still widespread.)

All in all, I personally would like to see Swing make the jump and start offering such possibilities as well. Actually, it's more like NetBeans and its Swing Designer that should come up with this kind of functionality, I guess.

Just my two cents.


Rock

2008/11/4 Stuart Halloway <stuart....@gmail.com>



--
Rocco

-----------------------------------------------------------------
"La realtà è quella cosa che, anche se smetti di crederci, non sparisce."

Philip K. Dick

Paul Drummond

unread,
Nov 4, 2008, 11:13:20 AM11/4/08
to clo...@googlegroups.com
2008/11/4 Stuart Halloway <stuart....@gmail.com>


For the book would people rather see Swing or Qt Jambi examples?

Personally, Qt Jambi definitely.  While Swing is the standard Java UI library it pales in comparison to Qt and is still under-supported by Sun IMO.  But if Qt licensing issues put people off then any free UI would be better than Swing!

Paul.
--
Iode Software Ltd, registered in England No. 6299803.

Registered Office Address: 12 Sancroft Drive, Houghton-le-Spring, Tyne & Wear, DH5 8NE.

This message is intended only for the use of the person(s) ("the intended recipient(s)") to whom it is addressed. It may contain information which is privileged and confidential within the meaning of applicable law. If you are not the intended recipient, please contact the sender as soon as possible. The views expressed in this communication may not necessarily be the views held by The Company.

graham

unread,
Nov 4, 2008, 11:47:06 AM11/4/08
to Clojure
> For the book would people rather see Swing or Qt Jambi examples?

I would rather see Swing. I have no experience of either, or opinion
on which is better but I would rather not have to download a 3rd party
library to follow the examples in the book (which I'm really looking
forward to!).

Graham

Geoffrey Teale

unread,
Nov 4, 2008, 12:06:21 PM11/4/08
to clo...@googlegroups.com


> For the book would people rather see Swing or Qt Jambi examples?

I practice Qt Jambi is a much better UI layer than Swing, but then so is SWT.

If you teach the general principles of Clojure then using any of them should be easy enough.   As Graham said, it's better to stick with the out of the box GUI layer for a general purpose book.   Qt Jambi was actually a little tricky to set up on my (rather esoteric!) Linux box, and you don't want readers to get pissed off and give up!

For the record I am currently playing with Qt Jambi and converting some examples over to Clojure which I might post on my blog at some point.

--
Geoff Teale
Freelance Software and Technology Consultant
Munich, Germany


Matthias Benkard

unread,
Nov 4, 2008, 12:11:14 PM11/4/08
to Clojure
On Nov 4, 4:26 pm, Chouser <chou...@gmail.com> wrote:
> One possible approach is with Qt Jambi.  They have a nice GUI builder
> called "designer" that generates an xml file that can be loaded at
> runtime.

Its free license is incompatible with Clojure's, though, so you'd need
to buy a commercial license, right?

Matthias

Matthias Benkard

unread,
Nov 4, 2008, 12:13:25 PM11/4/08
to Clojure
On Nov 4, 6:11 pm, Matthias Benkard <mulkiat...@gmail.com> wrote:
> Its free license is incompatible with Clojure's, though, so you'd need
> to buy a commercial license, right?
>
> Matthias

Oh, I'm wrong! That's nice. :)

http://doc.trolltech.com/4.4/license-gpl-exceptions.html

Matthias

Justin Henzie

unread,
Nov 4, 2008, 11:56:58 AM11/4/08
to Clojure
My preference is that the book focuses on the default java stack.

I am hoping that the book can demonstrate the simplicity of developing
with clojure and avoiding additional configuration and downloading of
significant libraries and frameworks that might dilute that message.

That being said, I am hoping that we will see a W3 section using
compojure.

-Justin



On Nov 4, 7:32 am, Stuart Halloway <stuart.hallo...@gmail.com> wrote:
> For the book would people rather see Swing or Qt Jambi examples? Or  
> something else? The book won't spend more than 10 of 250 pages on UI  
> stuff, so I'd rather do one reasonably interesting example than skim  
> several.
>
> Stuart
>

MikeM

unread,
Nov 4, 2008, 12:41:37 PM11/4/08
to Clojure

> For the book would people rather see Swing or Qt Jambi examples?
I use Swing occasionally, and have never used Qt, but I'd vote for Qt
examples to see how it compares.

Rich Hickey

unread,
Nov 4, 2008, 1:27:45 PM11/4/08
to Clojure


On Nov 4, 11:56 am, Justin Henzie <jhen...@mac.com> wrote:
> My preference is that the book focuses on the default java stack.
>

+1

I know people have built UIs with Netbean's Matisse, which is supposed
to be very good, and wired them up with Clojure. IMO that's a
promising approach.

Rich

Rocco Orlando Rossi

unread,
Nov 4, 2008, 4:00:05 PM11/4/08
to clo...@googlegroups.com
Actually I've just succeeded in doing that :) I'll post some instructions if anybody wishes. It's straightforward enough. But still, the code that Matisse generates is Java. Not that there's necessarily anything wrong with that. Maybe I'm biased because of my prior experience with GTK, Glade, and LibGlade, I suppose. It would have been interesting though to have the option of loading the interface dynamically during runtime, without generating any real code except for the XML file containing the details of the GUI. But I guess that the Java approach is equally effective and flexible in the end.

Rock

2008/11/4 Rich Hickey <richh...@gmail.com>

Paul Drummond

unread,
Nov 4, 2008, 5:02:25 PM11/4/08
to clo...@googlegroups.com
2008/11/4 Rich Hickey <richh...@gmail.com>
I know people have built UIs with Netbean's Matisse, which is supposed
to be very good, and wired them up with Clojure. IMO that's a
promising approach.

I have quite a lot of experience with Swing/Qt so for once I can contribute something informative (and overly subjective!) to the discussion :-)

Matisse is very good as far as *Swing* UI designers go (there arn't many) but compared to Qt and Qt Designer there is no comparision IMO - designer wins hands down.  It really is a beautiful tool and it makes UI design a breeze (and actually enjoyable!).  I always wonder why the Matisse team didn't copy some of Trolltech's (sorry, Qt Software's) ideas more. The way it handles layout is so intuitive - it's the best example of layout management I've seen of any UI toolkit (and that includes anything Microsoft charge for).  The quality is generally true of Qt in general.

In contrast, trying to cobble together anything more sophisticated that a simple dialog in Swing is awkward (not to mention ugly!) and the only decent designer is the aformentioned Matisse - its main downfall being its dependence on NetBeans and it's awful automated code-generation.  (Incidently, Qt Designer generates language-neutral XML files which are then converted into C++/Java/Python source code etc by compilers, usually as part of a build step.)

Appologies this feels like a Swing bashing - it's not intentional.  I've had to endure Swing at work for *too* long!

FYI - Qt Jambi Webstart demo: http://dist.trolltech.com/developer/download/webstart/qtjambi.jnlp

Cheers,
Paul.

Brian Carper

unread,
Nov 4, 2008, 5:26:25 PM11/4/08
to Clojure
On Nov 4, 9:06 am, "Geoffrey Teale" <tea...@googlemail.com> wrote:
> If you teach the general principles of Clojure then using any of them should
> be easy enough.   As Graham said, it's better to stick with the out of the
> box GUI layer for a general purpose book.   Qt Jambi was actually a little
> tricky to set up on my (rather esoteric!) Linux box, and you don't want
> readers to get pissed off and give up!

I blogged a little about Qt Jambi + Clojure recently [1], for what
it's worth. I found it very easy to set up and use, on Gentoo Linux
and on Vista. I'm using it to build an app in my spare time and it's
working well. I would be interested to see anyone write up a HOWTO
for using a GUI builder tool with Clojure, for Swing or Qt or any
other framework. It is a bit tedious to do by hand.

I agree though, for a book it might be better to stick with native
Java stuff. No sense needlessly complicating matters with external
libraries. Qt Jambi had a couple of odd quirks that I was unable to
figure out. (Randomly killing my Clojure process under SLIME for
example.)

[1] http://briancarper.net/2008/10/31/qt4-in-lisp/

--Brian

wubbie

unread,
Dec 11, 2008, 10:19:50 PM12/11/08
to Clojure
Hi,
The same hello world did not work for me.
The error msgs are:
(defn hello-world []
(qt4
(let [app (QCoreApplication/instance)
button (new QPushButton "Go Clojure Go")]
(.. button clicked (connect app "quit()"))
(doto button
(resize 250 100)
(setFont (new QFont "Deja Vu Sans" 18 (.. QFont$Weight Bold
value)))
(setWindowTitle "Go Clojure Go")
(show)))))
java.lang.Exception: Unable to resolve symbol: resize in this context
(NO_SOURCE_FILE:44)


Sun



On Nov 4, 5:26 pm, Brian Carper <briancar...@gmail.com> wrote:
> On Nov 4, 9:06 am, "Geoffrey Teale" <tea...@googlemail.com> wrote:
>
> > If you teach the general principles ofClojurethen using any of them should
> > be easy enough. As Graham said, it's better to stick with the out of the
> > box GUI layer for a general purpose book. QtJambi was actually a little
> > tricky to set up on my (rather esoteric!) Linux box, and you don't want
> > readers to get pissed off and give up!
>
> I blogged a little aboutQtJambi +Clojurerecently [1], for what
> it's worth. I found it very easy to set up and use, on Gentoo Linux
> and on Vista. I'm using it to build an app in my spare time and it's
> working well. I would be interested to see anyone write up a HOWTO
> for using a GUI builder tool withClojure, for Swing orQtor any
> other framework. It is a bit tedious to do by hand.
>
> I agree though, for a book it might be better to stick with native
> Java stuff. No sense needlessly complicating matters with external
> libraries. QtJambi had a couple of odd quirks that I was unable to
> figure out. (Randomly killing myClojureprocess under SLIME for

Geoffrey Teale

unread,
Dec 12, 2008, 4:29:40 AM12/12/08
to clo...@googlegroups.com


2008/12/12 wubbie <sun...@gmail.com>


Hi,
The same hello world did not work for me.
The error msgs are:
(defn hello-world []
 (qt4
  (let [app (QCoreApplication/instance)
        button (new QPushButton "Go Clojure Go")]
    (.. button clicked (connect app "quit()"))
    (doto button
      (resize 250 100)
      (setFont (new QFont "Deja Vu Sans" 18 (.. QFont$Weight Bold
value)))
      (setWindowTitle "Go Clojure Go")
      (show)))))
java.lang.Exception: Unable to resolve symbol: resize in this context
(NO_SOURCE_FILE:44)


Hi,

Depending on which version of Clojure you are using you may find that you need to change:

(doto button
    (resize 250 100))

to:

(doto button
 

--
Geoffrey Teale

Geoffrey Teale

unread,
Dec 12, 2008, 4:32:19 AM12/12/08
to clo...@googlegroups.com


2008/12/12 Geoffrey Teale <tea...@googlemail.com>



Hi,

Depending on which version of Clojure you are using you may find that you need to change:

(doto button
    (resize 250 100))

to:

(doto button

Argh.. goddam google mail... I meant to say:

(doto button
    (.resize 250 100))

Note the additional dot in the notation.   There are a number of gotchas using QtJambi with post AOT versions of Clojure.  I have spent a few weekends converting a program.   I will blog when my code reaches a useful stage and my current Qt branch is checked into github.   

prhlava

unread,
Dec 12, 2008, 6:19:37 AM12/12/08
to Clojure

Swing - as it comes built in with java....

Vlad

prhlava

unread,
Dec 12, 2008, 6:26:34 AM12/12/08
to Clojure

Hello Rock,

> Does anyone know of such a possibility? And, if not, what are the
> chances of coming up with a tool like that? I'm not a Java nor a Swing
> expert, so I haven't the faintest clue as to what the difficulties may
> be.

There is such a tool for jruby (which I tried for a basic gui) called
monkeybars:

http://monkeybars.rubyforge.org/

It would be a perfect candidate for borrowing the concept and
approach...

Basically, one uses netbeans (but it is not tied to netbeans) swing
gui builder to define the gui, the monkeybars does the plumbing and
the programmer uses jruby to do the programming in ruby...

Kind regards,

Vlad

PS: The jruby is ruby language implementation running on java virtual
machine...

levand

unread,
Dec 12, 2008, 4:47:52 PM12/12/08
to Clojure
My vote is for Swing. Despite its flaws, it's the Java standard -
there's no need to worry about compatibility (SWT) or licensing
(Jambi) issues, and there's a wealth of material online to study it
further. It's included with Java, which is a huge plus in a tutorial
setting - personally, I'd be very turned off if I had to download and
configure an additional library just to follow the examples in a book.
And a lot more programmers are going to be familiar with Swing than
any of the others.

Plus, in 15 pages, you're not going to be able to cover any reasonable
amount of any library, so really, the library itself doesn't matter as
much. What's more important is showing how to use Clojure to interact
with Java in a variety of more complex UI scenarios, which Swing
offers. Once those concepts are grasped, the actual library is
immaterial.

Just my two cents.

-Luke

On Nov 4, 10:32 am, Stuart Halloway <stuart.hallo...@gmail.com> wrote:
> For the book would people rather see Swing or Qt Jambi examples? Or  
> something else? The book won't spend more than 10 of 250 pages on UI  
> stuff, so I'd rather do one reasonably interesting example than skim  
> several.
>
> Stuart
>

wubbie

unread,
Dec 12, 2008, 9:02:19 PM12/12/08
to Clojure
Hi Geoffrey,

Thanks for the tip. I put . for every command within the doto.
Also looking forward to having a look at the Qt work you are
currently doing.

Cheers,
Sun
Reply all
Reply to author
Forward
0 new messages