Per has posted 1 posts at DZone. View Full User Profile

What you can do with Swing in your spare time

  • submit to reddit

This story begins in 2008, when we, Pär Sikö and Martin Gunnarsson, decided to try to get a presentation into Øredev. We had held a presentation covering the basics of Swing and Java2D at a local JUG meeting, but to present at a big conference, we needed a demo application to show our audiences that what we said wasn't just empty words. We both really enjoy working with graphical user interfaces, so there was no lack of motivation, but since this basically was a hobby project, we'd have to do it all in our spare time. That kind of set the tone for the whole project, and for this article. Since we didn't create this application for a big customer with unlimited resources, we didn't have to do everything by the book. No pre-studies, no design documents and no requirements. Instead, we tried out new things as we dreamed them up, which in the end led to a very nice, and slightly quirky application. The solutions we present in these articles worked for us, but they're not to be considered as universal rules of Swing development. With that said, let's get back to our story.

Since our application was just going to be a container for our main work, the cool user interface, one of our first problems was to figure our what kind of application we wanted to make. We soon settled on an RSS reader, mainly because the application logic is pretty simple, which is a good thing when you want to focus on the GUI. Since there ususally is a ready made implementation of just about anything you want to write in Java, we first took a look around for a nice feed library, and quicly found Project ROME, a very stable, open source RSS/Atom library.

We decided pretty early on that our killer feature was going to be a feed list with "kinetic scrolling", the smooth scrolling effect made popular by the Apple iPhone and iPod Touch. After some prototyping, this turned out to be easier than we thought, but more about that later. Aside from the feed list, we wanted a search box, profiles (saved searches) and a timeline to show feed items from a specific time period.

Feedjii in action

Accordion panel in action
Feedjii obviously doesn't look like a native application, and this was never our intention. In fact, we're pretty sure it doesn't follow a single design guideline. However, a custom look isn't always the best choice, it depends on your target users. If you're writing an application for people with limited computer experience, or say, for administrative staff at a company, you're probably better off trying to make your application look as familiar as possible - i.e. native. This will make it more trustworthy, and the users will at least have an idea about where to start looking for certain things. We've implemented the design of each component in its paintComponent method, but this is probably only suitable for small projects like Feedjii. For bigger applications, a custom look and feel is probably a better choice. There are a number of highly configurable LAF's out there, so you could get away without writing a single line of code. Using a LAF, you can also let the user select the look they prefer, or distribute different versions of your application to different users. This is also a very effective way to brand an application for a specific company or product.

We will continue this series of articles by deep diving into the implementation details and describe what we've done and how. We're also going to open source the project.

You can run the beta version here:

What's next? Well first of all we're going to talk at JavaOne and if you're attending we'd love to see you there. Our presentation is called "Swing Rocks - A Tribute to Filty Richs Clients", on Thursday June 4, at 9.30 AM, In Hall E 135.

Published at DZone with permission of its author, Per Siko.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Sergey Surikov replied on Sun, 2009/05/24 - 5:15pm Could not verify signing in resource:
    at Source)
    at com.sun.javaws.LaunchDownload.checkSignedResourcesHelper(Unknown Source)
    at com.sun.javaws.LaunchDownload.checkSignedResources(Unknown Source)
    at com.sun.javaws.Launcher.prepareLaunchFile(Unknown Source)
    at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
    at com.sun.javaws.Launcher.launch(Unknown Source)
    at com.sun.javaws.Main.launchApp(Unknown Source)
    at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
    at com.sun.javaws.Main$ Source)
    at Source)

Otengi Miloskov replied on Sun, 2009/05/24 - 9:39pm

Very nice sample, It looks that Swing still Rocks.

It could be great if the Java community do an effort to release Swing2 with more modern layouts included and optional declarative GUI with xml as xul.

Alan Ding replied on Mon, 2009/05/25 - 12:32am

cool. except it does not support wheel action

Martin Gunnarsson replied on Mon, 2009/05/25 - 2:09am

I've written a short post about the problems running Feedjii on mac. We hope to solve this problems soon!

Jochen Bedersdorfer replied on Tue, 2009/05/26 - 4:41pm

Looks like this is for windows users only :(

 That's what my Mac is saying:

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at com.sun.javaws.Launcher.executeApplication(
    at com.sun.javaws.Launcher.executeMainClass(
    at com.sun.javaws.Launcher.doLaunchApp(
Caused by: java.lang.NoClassDefFoundError: com/sun/awt/AWTUtilities
    at nu.epsilon.rss.ui.XFrame.main(
    ... 9 more
Caused by: java.lang.ClassNotFoundException: com.sun.awt.AWTUtilities

You are evil, sun-internal stuff users ! :) 



Alexander Pisarev replied on Tue, 2009/05/26 - 5:21pm in response to: Jochen Bedersdorfer

It's NOT for Windows-users only:) I'am using Linux and it's OK.

Jochen Bedersdorfer replied on Tue, 2009/05/26 - 5:37pm in response to: Alexander Pisarev

Alright Mr. know-it-all, let's just say it works only in SUN JVMs and similar ;)

Martin Gunnarsson replied on Wed, 2009/05/27 - 6:28am

We're working on the Mac issue, it will be fixed (or worked around), but perhaps not before JavaOne.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.