GUI development in scalafx


There is a scalafx webpage and it has detailed tutorial how to install scalafx and get started. However it is actually even simples as described there. When you have working scala environment (eclipse with scala IDE for example) make sure that you use jdk from oracle (includes javafx by default and you need javafx to use scalafx) and just download scalafx jars and include them in your project.

Available learning resources

Creating gui with scalafx isn't hard when you know how to use it.

If you know javafx you've probably seen ProJavaFX book. Good news! There's a scalafx equivalent in source code

A better scalafx API overview is ensemble project.

When help from available examples is not enough

Asking google doesn't provide many helpful examples. I tried to resolve some of my problems, but I couldn't find right answer usually. Which is different from for example problems with java, because there are usually lots of questions with answers.

But... it's not so bad. Scalafx source code is available and well written and you can just skim it and get your answers or translate your problem to javafx problem and then look for answer in java community.

Mixing scalafx with javafx

I didn't all issues in my code(I have some problems with responsivness with observable buffers) but I can already tell that scalafx works well with javafx.

I wanted to add some warning dialogs into my scalafx application, but scalafx or javafx don't support it by default. I found dialogs library for javafx and tried to use it to show dialog in my scalafx app. Guess what? It worked and doing it was really simple.

{% codeblock splitContentToSentences - MainApp.scala %} import javafx.scene.control.Dialogs (...) new Button("Submit") { onAction = {e: ActionEvent => val emptyFields = getEmptyFields() if(!emptyFields.isEmpty) { Dialogs.showWarningDialog(stage, emptyFields.mkString(", ") + " cannot be empty.", "Book couldn't be added.", "Adding failure"); } } (...)

Here's the library: javafx-dialogs

and descriptive blog post about how to use it.

And I forgot to add - scalafx looks quite well (like javafx) opposed to scala swing which looks just horrible. Scala swing sounds nice, it's simple, is available by default, has scaladoc... but don't get deceived. Scala swing looks old, api makes strange suprises, and its development is a lie. Just use something else instead, for example scalafx.

Opublikowano: | Źródło
Comments powered by Disqus