GUI in Scala/Groovy/Clojure

15,834

Solution 1

Scala comes with fairly complete sample applications for basic GUI elements, which you can run by typing scala scala.swing.test.UIDemo at the command line. You can browse the source code for them here.

You may also look at this document to get an idea of the design principles behind Scala's Swing wrappers.

Solution 2

DISCLAIMER: I'm a Clojure programmer. I'm obviously biased.

Of all of those languages, I think Clojure and Groovy are probably the most compact. Scala is a curly-bracket language like Java, so it tends to take up a bit more space. However, it's nowhere near as verbose as Java is, and I think Scala is pretty awesome. I know that Scala has a swing wrapper. I've never done GUI development in Scala, so I can't really say how it feels.

I've done some swing development in Clojure, and it doesn't really take much. Using swing direct from Clojure can be tedious until you write yourself some abstractions, but altogether, swing apps are smaller than the same thing in Java because Clojure code tends to be shorter and more concise than Java code.

Clojure also has some wrappers of sorts to make swing development more Clojury. One of which is clj-swing. I've seen some code written using it, and it's pretty cool, and definitely more concise than direct interop.

Now, I don't know Groovy. I really don't know much of anything about it, but I know it's more compact than Java, so I imagine GUI development would be fairly compact as well.

I think Clojure is a safe bet. With clj-swing, or even directly using the Java GUI toolkits directly is going to be really compact compared to Java, and the ability to build abstractions over non-compact stuff with macros is definitely a huge plus. Clojure has my vote.

Solution 3

Groovy has the Griffon framework which uses convention over configuration for building GUI apps on the JVM. It's similar to grails/rails but for a rich GUI rather than a web app.

Solution 4

Groovy has something called the swing builder for making GUI programming easier. Here is a piece of sample code from the groovy website, it creates a frame with a button and counts the number of times you click it:

int count = 0
new SwingBuilder().edt {
  frame(title:'Frame', size:[300,300], show: true) {
    borderLayout()
    textlabel = label(text:"Click the button!", constraints: BL.NORTH)
    button(text:'Click Me',
         actionPerformed: {count++; textlabel.text = "Clicked ${count} time(s)."; println "clicked"},
         constraints:BL.SOUTH)
  }
}

Solution 5

I am currently developing an SWT application in Scala and quite like it. But I do expect Clojure would be even more compact.

Share:
15,834
Alexander Gromnitsky
Author by

Alexander Gromnitsky

Updated on June 14, 2022

Comments

  • Alexander Gromnitsky
    Alexander Gromnitsky almost 2 years

    Last time I had to deal with Java was 2005 and I forgot almost everything about it since then.

    Today I need to build a GUI app on the top of Java. I guess it is better to use one of Scala/Groovy/Clojure languages.

    The question is: which of them is better for desktop GUI programming? My program will transform and display a series of jpeg/png files + there will be ~10 dialogs (with tons of options in each with all possible widgets).

    The main requirement is compactness: I hate to write a dozen lines of code only to draw a simple frame with a button. My background in GUI is (mostly) Tcl/Tk and GTK+.

  • nickik
    nickik almost 14 years
    I don't know mutch about griffon but didn't day say that they want to have wrappers for jruby and clojure? Remember hearing something like that.
  • Dónal
    Dónal almost 14 years
    Personally, I think Clojure is too obscure and immature for production code that may need to be maintained over a long time by many developers (though I don't know if that applies to this project). I'm not saying it's a good/bad language, but it's too different from Java for a Java developer to pick it up easily.
  • I82Much
    I82Much almost 14 years
    A) Thanks for the little easter egg about the UI demo. I had no idea that existed. Is the source for that available? B) I started using the Scala swing wrappers this weekend after about five years of standard Java swing experience. There's more than a bit of learning curve; it might be easier if you're new to GUI programming. I'll be making a blog post soon highlighting some of the differences.
  • Rayne
    Rayne almost 14 years
    If he has the option of these languages at work, obviously, they don't feel it's too "obscure and immature for production code." I think you should let him decide, since it's his application. Beyond that, I know of several companies that use Clojure as their/one of their primary languages, and are proud of it.
  • Daniel C. Sobral
    Daniel C. Sobral almost 14 years
    @I82Much The answer has a link to the source code. It should also come with standard Scala distributions -- which include source code for compiler and libraries -- and may be obtained as well with git and subversion.
  • Daniel C. Sobral
    Daniel C. Sobral almost 14 years
    @I82Much Also, I'd love to see that blog post. I think Scala lacks in blog posts about GUI programming.
  • I82Much
    I82Much almost 14 years
    I'm making a minesweeper clone in Scala. Almost finished. When it's in a releasable form I'll put a link here in the comments.
  • Daniel C. Sobral
    Daniel C. Sobral over 12 years
    @I82Much Did you ever finish that minesweeper app?
  • I82Much
    I82Much over 12 years
    Code is at github.com/I82Much/Scala-Minesweeper . Not completely done but not working on it anymore
  • Andres Almiray
    Andres Almiray over 12 years
    Griffon supports polyglot programming via plugins. Groovy, Java, Clojure, Scala, Mirah, Jython are some of the languages you can use with it.
  • user1558501
    user1558501 almost 11 years
    I've used seesaw (github.com/daveray/seesaw) before, it's extremely compact and elegant. It also plays very nicely with Clojure's data structures, enabling easy binding between atoms and swing components in both directions.
  • Bjorn
    Bjorn over 10 years
    The linked to document is a 404 now. :(
  • Daniel C. Sobral
    Daniel C. Sobral over 10 years
    @BjornTipling Thanks for calling my attention to it. I have updated both links to their present locations.
  • Patrick Refondini
    Patrick Refondini over 9 years
    Sample applications mentioned in original post are currently found at scala-swing github sub-project