10 ms·
Show HN: Sierra, a DSL for building Java Swing applications
Yes, I know hardly anyone uses Swing anymore. :-) I basically just did it for fun and thought I would share.
- euroderf 4y agoA DSL is nifty. Does anyone know of anything similar for Go ?
- hestefisk 4y ago[ insert random Wayne’s World reference here ]
- samsquire 4y agoThank you for doing this. I've maintained or built Swing applications for work and at university. One was a game. I hope I'm not the only one who feels frontend programming is difficult to get right and to get maintainable software. I would like to learn Qt but the C++ is a barrier to learning it.
- jeffreportmill1 4y agoThis is very nice! It is easy to get lost in most raw Swing code, but this seems to result in hierarchically defined code that keeps nested UI elements in context. I can almost visualize the resulting UI from the code.
- tannhaeuser 4y ago> Yes, I know hardly anyone uses Swing anymore. Actually, Swing is the GUI toolkit used by IntelliJ IDEA, one of the few if not the only commercially successful and kick-ass Java desktop app(s).
- gk_brown 4y agoAgreed. I said as much in my response to this issue that was opened the other day: https://github.com/HTTP-RPC/Sierra/issues/12 https://github.com/HTTP-RPC/Sierra/issues/12
- jeffreportmill1 4y agoThe only real problem with Swing is that there was never a version 2. If it had been separated from AWT, updated some of the APIs and given a modern look-and-feel, it would still be relevant today. JavaFX is nice, but it broke too many conventions. And, of course, Oracle or OpenJDK (or someone) needed to invest in a browser port of the JVM, which is totally possible these days.
- gk_brown 4y agoTake a look at FlatLAF: https://github.com/JFormDesigner/FlatLaf https://github.com/JFormDesigner/FlatLaf They have done a great job bringing a modern appearance to the Swing components.
- whartung 4y agoNetBeans switched to FlatLaf, and looks pretty good. As I understand it, IDEA has done a lot of "Swing Work". I don't know if it's just augmenting existing or creating a bunch of new controls or if they delved deeper. It's just my understanding that IDEA is Swing, but not as we know it. I could be wrong. NetBeans is pretty much pure Swing.
- neuronexmachina 4y agoFor their next-gen Fleet IDE though, it looks like Jetbrains is using Kotlin and Skia/skiko? * https://blog.jetbrains.com/fleet/2022/01/fleet-below-deck-part-i-architecture-overview/ https://blog.jetbrains.com/fleet/2022/01/fleet-below-deck-pa... * https://twitter.com/jetbrains_fleet/status/1465311231271739396 https://twitter.com/jetbrains_fleet/status/14653112312717393... * https://github.com/JetBrains/skiko https://github.com/JetBrains/skiko
- kitd 4y agoThis looks really cool. Applying a thin layer over parts of the standard library is a very good idea IMO. Reduces the dependency tree but a lot. One question (my Swing knowledge is at least 15 years old!): what's the simplest way to handle events using this? Eg taking the FormTest [1] example, how might one simply bind a model object to the UI elements? [1] https://github.com/HTTP-RPC/Sierra/blob/master/sierra-test/src/main/java/org/httprpc/sierra/FormTest.java https://github.com/HTTP-RPC/Sierra/blob/master/sierra-test/s...
- exabrial 4y agoI wish there was CDI integration with Swing or JavaFX and you can annotate handlers
- gk_brown 4y agoGreat question. You can do this with a cell consumer (i.e. the with() method). See OrientationTest for an example (e.g. leftToRightButton, rightToLeftButton): https://github.com/HTTP-RPC/Sierra/blob/master/sierra-test/src/main/java/org/httprpc/sierra/OrientationTest.java https://github.com/HTTP-RPC/Sierra/blob/master/sierra-test/s... I should probably add a better example.
- gk_brown 4y agoAdded an example demonstrating how to add an action listener to a button: https://github.com/HTTP-RPC/Sierra/blob/master/sierra-test/src/main/java/org/httprpc/sierra/ActionTest.java https://github.com/HTTP-RPC/Sierra/blob/master/sierra-test/s... I'm not sure it's exactly what you were looking for, but hopefully it is similar enough.
- kitd 4y agoThat's great! As I say, my swing experience is very old and it's probably just a case of remembering the basic action framework more than anything else. But that fits in very nicely with how your library works using with().
- Pet_Ant 4y agoWas hoping this meant the resurrection of JavaFxScript/Visage: https://en.wikipedia.org/wiki/JavaFX_Script#Syntax https://en.wikipedia.org/wiki/JavaFX_Script#Syntax
- vips7L 4y agoYou might like Groovy’s SwingBuilder: http://groovy-lang.org/swing.html http://groovy-lang.org/swing.html
- gk_brown 4y agoSierra 1.0 and 1.1 actually took a similar approach - trying to create a DSL based on the standard layout managers. However, I ultimately found that approach too limiting and went with custom layout managers for version 1.2.
- Manjuuu 4y agoThis looks nice, finally a good attempt at a java Swift UI, will try it out.
- gk_brown 4y agoSierra is actually inspired by Lima, a UIKit DSL I created in Swift before SwiftUI was announced: https://github.com/HTTP-RPC/Lima https://github.com/HTTP-RPC/Lima
- phoronixrly 4y agoI'd use this every day in place of $JS-framework-of-the-day + HTML + CSS, alas...
- xrrocha 4y agoThis is reminiscent of JavaFX's original F3 formulation (aka JavaFX Script): object literals reflecting the GUI visual structure. JavaFX started out as a Java library on top of Swing but the lack of object literals and lambdas led to the creation of the F3 language (code-named foo for "funcional object-oriented"). Despite Java's progress since then its syntax still feels somewhat rigid. Sierra looks very nice indeed. It could benefit from a more fluid, less syntax-encumbered DSL laid on top of it in Kotlin or Scala.
- gk_brown 4y agoThanks for the feedback. I did consider using Kotlin but wanted to make sure it worked at least minimally in Java first.
- xrrocha 4y agoYeah, Implementing the framework as such in Java with no other dependencies is a sound decision, imho. Laying out a Kotlin DSL on top of it could be an excellent opt-in feature to leverage the core in a more declarative way
- Dirak 4y agoThis is slightly off-topic, but this post makes me feel sincerely nostalgic for building games in Eclipse and Swing back in the day. Growing up, Notch's live streams[1] where he would code up a game in Java Swing for Ludum Dare were one of my first exposures to programming, and reasons for eventually studying CS. I wish there were some modern alternative to Swing that would be as simple as Swing, but would allow you to create games for the web. [1] https://www.youtube.com/watch?v=4J_8HkQj9mU https://www.youtube.com/watch?v=4J_8HkQj9mU
- exabrial 4y agoAgree, swing was "terrible" because desktop programming is hard (so many event sources!) but it contained a lot less footguns than say, QT or GTK. JavaFX is sorta the spiritual successor to swing. On linux, you can actually run it straight from the framebuffer! (No 'desktop' needed!) There was also this discussion a long while back: https://news.ycombinator.com/item?id=25121705 https://news.ycombinator.com/item?id=25121705 The project is actively maintained and sees commits quite a bit! Might be what you're looking for.
- gk_brown 4y agoHave you looked into Flutter at all? I admit that I have not, but I know it supports web development in addition to mobile and desktop: https://flutter.dev/multi-platform/web https://flutter.dev/multi-platform/web
- t0astbread 4y agoIt's not exactly the same but if you're looking for a simple environment that lets you create games for the web, you should check out the PICO-8: https://www.lexaloffle.com/pico-8.php https://www.lexaloffle.com/pico-8.php
- layer8 4y agoIt’s nice to see new developments for Swing, however GroupLayout is the only layout manager I ever needed in practice. Once you grok the combination of parallel/sequential with horizontal/vertical, it’s most flexible and quite intuitive, and is also close to declarative in syntax.
- KronisLV 4y agoI really like the examples: a screenshot of what the thing looks like, with a link to the corresponding source code right next to it! I think all UI component frameworks (or DSLs, I guess) should have something like that. Some webdev libraries/frameworks have gone a step further and include code in the same page (though maybe it could/should be collapsed by default sometimes).
- gk_brown 4y agoI generally prefer links since otherwise the code and examples can easily get out of sync.
- thewataccount 4y agoI really like this as a casual user that is going to just scroll through the page and see what it looks like - I wouldn't go out of my way to click on the examples. This might be useful as an overview of what it is more then live examples
- Eumenes 4y agoMake Swing Great Again!