Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Hacker News desktop application in Kotlin/Swing (github.com/westoncb)
141 points by westoncb on Oct 7, 2017 | hide | past | favorite | 90 comments


The other day there was a post recommending the use of JavaFX.

I would really like to see a non-trivial app built on JavaFX in Kotlin, with the following properties:

- Does not look ugly.

- Is not composed of _merely_ OEM widgets. But includes custom elements, like one would normally see on websites (and by extension, Electron apps).

- Is lightweight and response, not just in terms of CPU and RAM, but in terms of user experience (think VSCode vs Android Studio).


Not sure it meets all 3 requirements, but last time I tried I was rather impressed by the Nightcode Clojure IDE built with JavaFX:

https://sekao.net/nightcode/


Oh, I didn't know that was written in JavaFX. I used it a lot when I was first getting into Lisp languages. It's pretty sweet.


I made JavaFX app for my company. It is in the gambling space. Used to display jackpot related stuff, winners, current jackpots, promotions, etc. It is deployed to every betting shop (around 600 of them). It also interacts with central server and gambling machines.

I started with swing then shortly thereafter switched to JavaFX and it was a joy to use it for this usecase. Really easy to make what we needed in small amount of code and it is performing well and is really stable (runs 24h/7 without problems)


Disclosure: I am friends with the founder.

Gluon is taking a pretty neat approach with javafx (think reactive native with javafx):

http://gluonhq.com/

I haven't browsed their repos but if you were to look for anyone promoting jfx it would be these guys.


I actually did with my company and anyway it was a bad decision. JavaFX and swing customization is really not easy and not well documented. JavaFX uses custom XML which make no sense to be honest when you want to do nice design. And it requires custom CSS too.

Additionally, their design are bad(I mean their Java API).

We spend a whole year making an app with it, at the end we decided move away from it, like the rest of the java community if fact that do not really support desktop applications anymore.


> JavaFX uses custom XML which make no sense to be honest when you want to do nice design.

I don't see why the custom XML should be a problem. Definitely you are not supposed to edit the .fxml files by hand, especially when you have apps like Scene Builder that allow you to design everything from a GUI.

> And it requires custom CSS too.

That's true only for a few JavaFX-specific properties. The CSS syntax doesn't change very much. Also, it's not a surprising feature: QT, the C++ GUI framework, also uses custom CSS.


FX1 or FX2?


Btw, this project started when my sister and I were eating at Panera and decided it would be fun to each write an HN front-end. Hers was largely a project to learn React, which you can see here: http://coribeecroft.com/hacker-news-frontend/

She's looking for work at the moment if anyone knows of someone who might want to hire a somewhat junior but very smart developer with a good sense of humor. See here for more: http://coribeecroft.com


Her website is inspiring. I am also graduating this semester, I will compile my works similarly to her.

Hope she lands a great job.


I'd recommend adding README files to the public Github projects.


You were so preoccupied with wether you could, that you didn’t stop for one moment and think I’d you should!

Just joking. Good job. I think it’s been years seen I saw a Java App, and have to say, I am a bit disappointed at how Swing still looks.


Swing will always look like that. Java FX is the new stuff.


You can substantially improve appearance by change the default look and feel to something better, for example your platforms' look and feel.


Haha! Thanks! I can't really say this is representative of the best modern Swing has to offer, though, so I hope people won't judge it too much by my joke project ;)


Ask HN on Show HN: Why is Swing UI still so Ugly ?

2 Decades since it's introduction in 1997 ( I remember being forced to use it in a trading OMS application in 2002), Swing UI looks frozen in time, ugly as ever.


Part of that is because Java has basically moved onto JavaFX over Swing—and partly it's because I built this specifically to resemble old Swing apps :)


I love the old "metal" look and feel. It's retro-tastic! :)


Yay, someone else too! :)


Because most developers don't bother to read Sun tutorials and books like "Filthy Rich Clients".


I'm a big fan of FRC, but a lot of those techniques are about "special-case" UIs, the way you see them in Web UIs or "multimedia" applications, not pleasing form and widget layouts. That's a bit of an intermediate step between just spewing forth UI elements and constructing fluid animated, mirrored list displays. And sadly often neglected, especially if your tools don't take care of it automatically (layout engines, Interface Builder etc.). Java and Tcl didn't have to look that bad, but sadly they often do.

Or, well, one could just use JGoodies ;)


I agree with you.

Still it is a kind of first step.

Tooling was the major problem. Swing could be made to look as nice as WinForms, but defaults matter when developers are lazy.

Android is another example where if one wants to make cool Material design applications, some UI programming skill is needed.


"Filthy Rich Client" only shows how to do it, but it's still much, much harder than in QML (even Qt Widgets supported CSS styling) and WPF. I would say by a factor of at least 5 regarding QML and slightly less for WPF.


Yes, but it was possible.

Not reading such books, just meant many devs were totally unaware of how to do it.


intellij is swing and it looks decent. i think it's because most people don't spend any time on appearance.


IntelliJ is what a Swing app might look like after more than a decade of work and shipping (at times) with a custom-built JRE. It's not an effort most can and should spend to get to 'decent'.


follow up question: why does swing use its own special snowflake design, when it could the OS's native design?


Swing uses a pluggable 'look and feel' system (essentially themes)—which does include a 'native' look and feel for various OSs, including Windows and macOS.


Because Sun made the boneheaded decision (and never admitted it was dumb) to go for emulated widget controls instead of native ones. What this means is that they have had to reimplement and imitate the behavior of native controls on all platforms (realistically, Windows only) every time Microsoft came up with a new version.

In contrast, IBM took the native approach with SWT / JFace, and the interfaces written with that library look and feel infinitely more native and performant than Swing and JavaFX ever did and ever will.


The toolkit based on native widgets existed before Swing. It was called AWT.


AWT wasn't native either - it just had one ugly appearance and couldn't be themed. I seem to recall it kind of resembled Sun's CDE (Common Desktop Environment) so it would have look sort of at home on Solaris.


AWT uses native widgets.


AWT isn't native, it uses peers.

The fact that Swing ended up being such a massive failure was in good parts due to the fact that Swing is built on top of AWT.


Consistent look & feel between platforms.


Which means it sucks and looks weird on all platforms.

The story of Swing.


Or the story of Electron.


Which do you care more about: it works, or it looks good? There's a reason Java became such a big platform for business applications and it isn't because it cared about fashion fads.


> There's a reason Java became such a big platform for business applications and it isn't because it cared about fashion fads.

There's a reason why Java completely failed on the desktop: Swing.

> Which do you care more about: it works, or it looks good?

Both. I care about both. And you should too.

But Swing developers got used to only being able to have one. At most.


Completely failed? JetBrains' IDEs seem awfully popular, and they are all Java and Swing.


Can you name another very popular and very good looking Swing application?

Even if you can, you can count them on one hand. Swing was a massive failure, and rightfully so, because Swing/JavaFX apps look, and more importantly, feel, like a broken mess.

In contrast, SWT/JFace apps look a lot more native and feel extremely snappy. Apps build on the Eclipse RCP are in general pretty decent looking and they enable all the native controls and functionalities of the host platform.


Jetbrains IDEs could almost have an NCurses GUI, and they would be worth using. How pretty they are is mostly orthogonal.


> Both. I care about both. And you should too.

Why? What value is looking good? There's value in a well designed responsive UX, but how it looks is completely meaningless to me because it doesn't help me get shit done.


It is not only about looking good. Non-native widgets break user interaction is small but irritating ways.

If you are going for non-native widgets, they should at least look good. Otherwise you get the worst of both worlds.


What framework does Jetbrains use for all their tools? They honestly look and perform great on every platform that I have used them on.


Java Swing, with lots of manual tiny tweaks for fidelity.


Wow I had no idea, assumed it was JavaFX, it has a much nicer feel to it than the other 2 IDEs. Has Swing remained the same or has the API been overhauled since idk, SE6-ish around last I perused? NetBeans certainly has had a nice bit of a facelift last I saw of it. Eclipse I won’t say too much, looks like their splash screen is the only thing has had much of an overhaul.


Just tiny improvements, mostly bug fixes.

The secret is to read "Filthy Rich Clients" and "Tricks of Swing Gurus", where most of those programming knobs were described.


"great" is subjective, my preference is for "native" and then you only have to decide what you think/feel looks good just once. JetBrains doesn't look native.


Jesus. definitely looks like a swing app


Definitely got that swing feeling to it :)

Is there any way to customize the theme? I'd love something that's more clean and looks more modern.


You can get a bit closer to native feel with JavaFX. It's still not there but it at least the default Moderna theme doesn't rock the boat like Swing does.

Thankfully JavaFX is pretty easy to customise, it's roughly writing CSS, and there's a few high quality themes out there. Take a look at JFoeniX[0] for example for a material design inspired look.

[0]: https://github.com/jfoenixadmin/JFoenix


The only way is to change the Look and Feel, and unfortunately I think 'Nimbus' (which I show in one of the screenshots) is the most modern looking of the built-in Look and Feels. There may be some decent 3rd party options though... Like whatever IntelliJ is using.


Not true, you can get the platform feel easily. I've seen swing do Windows XP through 7 easily. Never tried 10 yet.


I tried using the platform look and feel on macOS, but it gives a number of important elements tiny heights, including comments, making them unreadable. I'm sure there's a fix but I haven't looked into it.


Ah, maybe it's been abandoned for JavaFX as others have pointed out?


Yes, there are several ways to custom paint, hence why there were several companies selling components like JGoodies.

The problem is that most devs don't bother to read the Sun tutorials and respective UI/UX blogs on java.net, or books like "Filthy Rich Clients".


This is why electron is so popular


As the author of this—yep, I can agree with that. I'm generally baffled when I see folks complain about Electron's slowness—but that's probably 'cause I started out building Swing apps :)


Also the memory usage is killer.


Memory usage is often a bad indicator of bloat. Especially GC languages like Java and JS will just go ahead and allocate a lot of memory from the OS without using all of it all the time. If you sum the "used" memory of all apps, it will often be more than the available RAM, even though there is no swapping going on. The OS memory management is really clever nowadays.

Actually, an app not using much memory may be sacrificing performance by not using a caching opportunity.

Unfortunately, apps coordinating how much memory to best use is an unsolved problem, as far as I know.


Is it really the case ? I would expect the language to expand the size of the heap only if after a GC the amount of free memory is still below a certain threshold.


I don't get that. Atom is only using 175 megs of ram on my mac. my email client is using more than double that.


On the other hand, the swing app has much better memory consumption than average electron app.


I think it has more to do with electron using JavaScript imo. JavaFx exists for a more modern java cross platform GUI


Add this to the list!

Other ways to read Hacker News | https://news.ycombinator.com/item?id=15310291 (Sep 2017, 181 comments)

Includes mention of alternate websites, mobile apps, and a pair of CLIs: haxor-news and hn-cli. I'm not sure but this might be the first desktop GUI app for HN I've heard of!


The HTML5 parsing in Java is awesome now! built a desktop app with Bootstrap 3 recently and the logic in Kotlin, fun stuff. Your Swing metal L&F is great :)


Very nice app and promising. However, I would the UI would look more "modern" (don't know if this is possible or not). Right now the button and the scrollbar is a bit outdated. The bonus point for me that this is written in Kotlin, not another Electron RAM killer app.


Very cool! I made a native macOS desktop client . It does use a web view to render the article but the article list, comments, voting, commencing, login interactions are all native . http://mackernews.com


Has anyone successfully compiled it with the kotlinc command line tool?


Hey anon6412, so this was my first Kotlin project, and I don't really know much at all on the ecosystem. I could check out kotlinc and write up something on how to build with it—I imagine it's just adding ./lib to the classpath, though I'm not sure. There's no package structure to the source.


It don’t mean a thing...


Haha I was very confused until:

"It Don't Mean a Thing (If It Ain't Got That Swing)" https://www.youtube.com/watch?v=qDQpZT3GhDg

:)


By the way there is still no HN OAUTH API. There are tricks to authenticate users and send messages but I don't want to share my password with a 3rd party.


this is awesome! i love the mix of age-old apis with a cutting edge programming language. this must've been really fun to code.


Haha, yep, it was a lot of fun. Especially going back and using Swing after about a decade of using other UI libs—that was a very interesting experience. When I was initially using Swing it was all I knew and at first I thought of all new systems in terms of it. I even tried re-writing a super stripped down version of it on OpenGL way back when: http://symbolflux.com/statichtml/oldprojects/openglguisystem... :)


Doesn't look like a regular jtree in the right pane, what did you use for showing the comment hierarchy?


It is a regular JTree! —mostly. I am using a custom TreeCellRenderer, which uses a JPanel with some labels on top, and a JTextPane for to display the comment itself (since the HN API gives back comments as html, I use JTextPane to parse/render that html).

Edit: it also may look different if you aren't used to seeing the 'Nimbus' Look and Feel—its JTree looks fairly different.


Some suggestions:

1) don't start a new project in Swing when you could use JavaFX instead. Since you're using Kotlin, you'd also want to use TornadoFX, a nice DSL for JavaFX.

2) use Maven or Gradle (or hell, any build tool). Don't store artifacts in source control.

I was really hoping someone who knew what they were doing was building this after the mini Electron debate earlier this week :/


Hey kevinherron—thanks for the feedback. I actually was aware I could build something nicer with JavaFX, but one of the main constraints on the project was that it satisfy my nostalgia for old Swing apps (particularly the 'Metal' Look and Feel), so I decided to go in that direction.

As for building—I agree the current project structure is basically unforgivable :) However, I figured the chances of anyone seeing the project were extremely remote and it was just for fun so I didn't bother with any of the boring stuff. Maybe I'll fix it up a little now though.

EDIT: the project now uses Maven.


Well, you posted it here, so the chances of someone seeing it got less remote.

Now that you've got a build.system in place you won't have to waste time documenting or replying to comments about how to build it :)


Excuse a quick aside -- do you know of any good examples of real non-enterprisey apps using JavaFX?

Java desktop apps seem almost universally awful, but it doesn't seem like it has to be that way. I'd love to see some counter examples (IntelliJ's IDEs are honourable exceptions, but they're a bit of a special case).


The old LoadUI (load testing tool) was written in JavaFX, you can still see the old screenshots in the documentation: https://www.loadui.org/working-with-loadui/projects.html

Also, there's LoadFX (a logging viewer) which was part of the rage post against Electron last week: https://github.com/renatoathaydes/LogFX

And Gluon keeps a list of sample apps:

http://gluonhq.com/developers/samples/


Cheers. I might have a go at some JavaFX stuff for fun sometime (or more likely TornadoFX with kotlin).


Bitwig, an excellent commercial cross-platform DAW, has a UI that is written with Java.


Thanks, looks interesting. Scriptable in javascript too.

I always note with irony that professionals expect to pay decent money (Bitwig is $400) for software relevant to their trade; the one exception being software pros.


Programmers have a deep Stockholm Syndrome for infinitely customizable software. They’ll disparage IDEa while installing enough plugins to turn vim into an incredibly poor one. Also, there’s the typical Real Programmer BS that asserts dev tools peaked in the 70s.


Visual Studio Enterprise is $2999/year, Pro is $539. Might as well add anywhere from $400 to $1500 for the IncrediBuild license.


It's really the expectations I was commenting on more than the pricing. I have heard devs on 100k plus whinge about $80 for a professional programmers editor, and rule out IntelliJ IDEs from their consideration because they're not 'free'.


When most "expensive" tools are put in terms of Starbucks lattes, they don't look bad. There's still the actual enterprise-targetted tier, but even up to the full Jetbrains Toolbox subscription, you're looking at what amounts to around a coffee a week.


That is peanuts compared with what other professionals have to pay for quality tools, specially if they require some kind of regular certifications.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: