<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Javafx on despatches</title><link>https://icle.es/tags/javafx/</link><description>Recent content in Javafx on despatches</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 19 Jun 2025 21:38:42 +0100</lastBuildDate><atom:link href="https://icle.es/tags/javafx/index.xml" rel="self" type="application/rss+xml"/><item><title>What I learnt developing a small JavaFX App</title><link>https://icle.es/2018/06/26/what-i-learnt-developing-a-small-javafx-app-wip/</link><pubDate>Tue, 26 Jun 2018 11:18:38 +0000</pubDate><guid>https://icle.es/2018/06/26/what-i-learnt-developing-a-small-javafx-app-wip/</guid><description>&lt;h1 id="introduction">Introduction&lt;/h1>
&lt;p>This is a collection of the things I learnt developing a simple JavaFX app over
the last month or two. My background is very much in Java EE with decades of
experience building high end, high-performance ticketing systems. This means
that my expectation from a development environment is relatively high. There are
many optional components in here that I find worthwhile setting up at the start,
but are not necessary&lt;/p></description><content:encoded><![CDATA[<h1 id="introduction">Introduction</h1>
<p>This is a collection of the things I learnt developing a simple JavaFX app over
the last month or two. My background is very much in Java EE with decades of
experience building high end, high-performance ticketing systems. This means
that my expectation from a development environment is relatively high. There are
many optional components in here that I find worthwhile setting up at the start,
but are not necessary</p>
<h2 id="tools">Tools</h2>
<h3 id="maven">Maven</h3>
<p>One of the most useful tools I have found while working with Java is maven. If
maven isn't a part of your build, have a look at it and re-evaluate that. I
have no doubt that maven has saved me hundreds, if not thousands of hours over
the last few years.</p>
<h3 id="javafx-scene-builder">JavaFX Scene Builder</h3>
<p>While this one has a bunch of issues and serious limitations, it can still be a
helpful tool. It helped me get a handle on the components available and placing
items.</p>
<h1 id="libraries">Libraries</h1>
<h2 id="testing">Testing</h2>
<p>I use <strong>junit5,</strong> but there are other options like test-ng which are equally
good. I use **Mockito **for mocking, but there are many other options like
PowerMock, JMockit, EasyMock, etc.</p>
<p>For UI Testing, you can use <strong>TestFX.</strong> I don't like UI work, so haven't done
much work with this.</p>
<pre><code>    org.junit.platform
    junit-platform-launcher
    1.2.0
    test


    org.junit.jupiter
    junit-jupiter-engine
    5.2.0
    test


    org.junit.vintage
    junit-vintage-engine
    5.2.0
    test



    org.mockito
    mockito-core
    2.18.3
    test
</code></pre>
<h2 id="logging">Logging</h2>
<p>I can&rsquo;t live without logging in any application. It can make troubleshooting
much easier, particularly when you&rsquo;ve deployed your app. <strong>log4j2</strong> is the main
logging framework out there. You can choose another one if you like, but I
strongly recommend having and using one.</p>
<pre><code>    org.apache.logging.log4j
    log4j-slf4j-impl
    2.11.0


    org.apache.logging.log4j
    log4j-api
    2.11.0


    org.apache.logging.log4j
    log4j-core
    2.11.0
</code></pre>
<h2 id="dependency-injection">Dependency Injection</h2>
<p>If you have working the Java EE Environment, you have almost certainly come
across
<a href="https://en.wikipedia.org/wiki/Inversion_of_control">Inversion of Control</a>, 
particularly in the form
of <a href="https://en.wikipedia.org/wiki/Dependency_injection">Dependency Injection</a>. I
love dependency injection. It helps with decoupling components and with testing.
I looked at various frameworks including
<a href="https://google.github.io/dagger/">Dagger 2</a>, <a href="https://spring.io/">Spring</a>,
<a href="https://github.com/google/guice">Guice</a>.</p>
<h3 id="dagger">Dagger</h3>
<p>The fully static (compile time) nature of Dagger 2 means that it doesn't gel
well with JavaFX which is very dynamic.</p>
<h3 id="spring">Spring</h3>
<p>I had worked with Spring many years ago and didn't want to tangle with a
behemoth for a small project. There are many components and loads of
functionality in spring and if you building a large and complex project, it
might be worth it.</p>
<h3 id="google-guice">Google Guice</h3>
<p>Google Guice is the framework that I ended up going with. It does have some
dependencies like Guava, but as it turned out, I Guava comes in handy for JavaFX
anyway. We don't need an entry in the pom.xml for this because of the following
dependency.</p>
<h2 id="gluon-ignite">Gluon Ignite</h2>
<p><a href="https://gluonhq.com/labs/ignite/">Gluon Ignite</a> was released by gluon labs to
integrate Dependency Injection frameworks with JavaFX. In other words, it ties
in the DI framework with the FXMLLoader so that it will load the correct
controller instances. Since I am using Guice, I needed the ignore-guice module.
If you add this into your pom.xml, it will also pull in google guice. Easy eh?
;)</p>
<pre><code>    com.gluonhq
    ignite-guice
    1.0.2
</code></pre>
<p>If you don't want to add another dependency, you could take a look at the code
in this module. It's fairly straightforward to integrate that manually into
your app. It's just easier to add in the dependency and let it do the magic</p>
<h2 id="event--publisher--subscriber-framework">Event / Publisher / Subscriber Framework</h2>
<p>It is likely that you will need an event framework or a publisher/subscriber
framework. The nature of GUI design and work is that it is an easy and simple
solution for a number of problems you will come across. Fortunately, we already
have an
<a href="https://github.com/google/guava/wiki/EventBusExplained">event framework</a> in
place within <a href="https://github.com/google/guava">Guava</a> which is a dependency of
Google Guice.</p>
<h2 id="project-lombok">Project Lombok</h2>
<p>Don't you love adding in a getter and a setter for each field? When you change
your fields, don't you love going in and updating all the getters and setters?
How about defining the long, pita to type types with generics of variables that
you are assigning from a method call? I mean the compiler can't possibly figure
that out by itself, right? How about writing out the toString, equals and
hashCode for each class? What do you mean no, you don't? You don't love these
tedious repetitive tasks of development? Good! You will love
<a href="https://projectlombok.org/setup/eclipse">Lombok.</a> Unfortunately, with Lombok,
it's not as simple as adding it into your pom.xml. Check out the install
instructions on their website for you IDE etc. You also need it in your pom.xml.</p>
<pre><code>    org.projectlombok
    lombok
    1.18.0
    provided
</code></pre>
<p>There is some controversy around Lombok. There is a
<a href="https://stackoverflow.com/questions/3852091/is-it-safe-to-use-project-lombok">good post on stackoverflow that covers some of these things in a reasonable fashion</a>.</p>
<h2 id="apache-commons">Apache Commons</h2>
<p>Last but certainly not least, we have
<a href="https://commons.apache.org/">apache commons</a>. This is a collection of libraries
rather than a single one. You know all those bits of code you write over and
over. Chances are that there is something in here that does it better and in a
simpler way.</p>
<h2 id="persistence">Persistence</h2>
<p>TBC</p>
<h1 id="packaging">Packaging</h1>
<p>TBC</p>
]]></content:encoded></item></channel></rss>