Question

I want to leverage the Scala's Actor Framework while I develop the user interface in the familiar Swing way.

Is it possible to have a mixed Java - Scala project in Eclipse, NetBeans or any other IDE?

Was it helpful?

Solution

Intellij does a good job of supporting mixed Java / Scala projects. At the moment the Scala support in Intellij seems better to me than the Scala IDE for Eclipse. (I have been a long time Eclipse user, recently trying Intellij on the recommendation of some other Scala coders).

OTHER TIPS

The "official" Scala plugin for Eclipse allows you to add the "scala nature" to any project, alongside the java nature. This allows you to mix and match however you'd wish.

I was playing with scala for the first time last night, using the Eclipse IDE, and it works very well.


Also, I just ran across this article: http://www.codecommit.com/blog/scala/joint-compilation-of-scala-and-java-sources

Seems that scalac knows enough about java to be able to resolve dependencies on java source, without actually compiling them. Very smart.

Mixing JAVA (Netbeans GUI-Builder) and Scala-Swing:

I just created a new JPanel with the GUI-Builder and some controls and simple logic.

Then created a scala object like seen in Scala-Swing tutorials:

object MySampleView extends Frame { title = "SomeTitle" ...

Then i added the new JPanel to the contents:

   contents = new Component { override lazy val peer = new MySampleJPanel() }

When compiling the project i see every change of the JPanel in GUI-Builder Cool.

Have you tried Scala's Swing wrapper? It's very lightweight in the sense that you've always access to the underlying Swing classes but it's very well thought out. I've found it pleasant to work with - the reactions pattern makes event handling so much easier and the actor framework makes event propagation so much clearer than using PropertyChangeSupport

It's perfectly possible to use it with your own custom Swing widgets too.

I've successfully mixed Java and Scala in my app. It runs in the Goggle App Engine and I use Spring MVC for the UI. (will port to Lift later)

The plugins for Intellij are a great help. Though it is still early days and there are occasional problems. (for instance the Scala plugin compiler does not seem to like JDO enhanced Java classes too much...there is a work around and I am sure this bug will be fixed soon).

The only thing I find a bit tedious about the mix is dealing with Java APIs that return Java collection class in Scala. Its very clunky and you have to jump through hoops a bit.

The Scala plugins for NetBeans are doing well too. With Swing development made so easy with NetBeans, it might just be what you are looking for :)

Great!!! Thank you for sharing the idea.

Just to complement, the code below made use of a GUI editor (I'm using WindowBuilder + Eclipse + Scala Plugin) to design the GUI and then everything else can be done using Scala. Now it's possible to use a Java Swing GUI editor and do all the programming in Scala.

import swing._
import event._
object TestApp extends Frame {
def main(args: Array[String]): Unit = {
    title = "Scala Swing Test App"
    val gui = new MyTestPanel() // a JPanel class from the GUI Editor
    val button = new Button {override lazy val peer = gui.getBtnMyButton()}
            // getBtnMyButton() is generated in the Gui Editor (Expose Component)
    contents = new Component{ override lazy val peer = gui }
    this.listenTo(button)
    reactions += {
        case ButtonClicked(b) => println("BUTTON CLICK.")
    }
    this.visible = true
} }

Mvackel

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top