How to use SimpleSwingApplication in Scala 3

Hello,
I’m trying to port an existing UI app to Scala 3 and I can compile all sources without errors but when I’m running the main class (extends SimpleSwingApplication) nothing happens, program just exits quietly (no errors).
In Scala 2 all I had to do was to extend that base class and then define the “top” function:
def top = new MainFrame {
// title, preferredSize, contents, resizable, listenTo, reactions
}
And the base class’ main function took care of the rest. Does anyone know if there are additional steps I need to take when using SimpleSwingApplication in Scala 3?
I would appreciate any help in this matter, maybe someone knows of an example I can look at.
Thanks!

What versions of: ‘scala-swing’, Scala, and SBT are you using. I’m able to do what you described with Scala “3.6.3”, sbt.version = 1.10.7 and dependency
"org.scala-lang.modules" %% "scala-swing" % "3.0.0"

Thank you for looking into this. I changed sbt version from 1.6.1 to 1.10.7 but the error did not go away. But since you were able to run the Swing app without any issues I added more debug to my app and I noticed that one of the function calls, ImageIO.read(), was failing at random. My code sometimes loads 2 images, then fails (quietly), and sometimes it loads 6 images, then fails, when executed through sbt.
To make sure I ran sbt assembly and ran my app using java command, with memory settings and a jar file. That worked without any issues. So I’m guessing that sbt does not have enough memory to run my app. I will look for some info on how to set memory limits for sbt 1.10.7.
Thank you for taking the time to answer my question, you put me on the right track =)

1 Like

Good catch.

Maybe instead of giving SBT higher memory limits (sbt Troubleshoot Memory Issues), you could experiment with fork (sbt Forking).

Compile / run / fork := true

I don’t remember if I ever needed to use SBT fork for memory issues. I think I used fork once because the app would call System.exit and that would cause SBT to terminate (took me a while to realize the cause).

1 Like

My swing application does not compile anymore.
I don’t know what is the problem.

One other thing that I needed to change to make my Swing app run was the definition of the “top” function. The change I needed to make was from “def top() = …” to “def top = …”. Looks like the new “top” function is not using parentheses anymore. Without that change my code would not compile (because “top” function did not match the base class definition).
I hope this helps.

1 Like

Alain, So that your question/problem doesn’t get lost, I recommend you start a new thread like that “swing application does not compile anymore”, explain the setup, and specific error messages you are seeing.