Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  What would you modify in Swing if you had to rewrite it?  (Read 4273 times)
0 Members and 1 Guest are viewing this topic.
Offline gouessej
« Posted 2013-07-25 12:00:08 »

Hi

I use several APIs to write GUIs including SWT, Swing, Netbeans RCP and Eclipse RCP. I have a lot of experience with Swing, I know it has some design flaws, it is sometimes cumbersome to use and its hardware accelerated pipelines don't allow to get consistent speedups. According to some (unconfirmed) rumors, some source code is simply copied from AWT to JavaFX which will make it difficult to run under Android. I assume PureSwing required a lot of work, I don't feel able to rewrite Swing alone even though there is already an hardware accelerated implementation of Graphics2D based on JOGL (GLG2D). What would you modify in Swing if you had to rewrite it?

Personally, I would try to make the following changes:
- support touch screens and multi-touch (in the same way NEWT does)
- support gamepads
- add a build-in charting API (like JavaFX)
- better separate the general behavior of components from the look and feel
- emulate native look and feels instead of relying on native features
- use OpenGL hardware acceleration to draw every components
- try to remove some non uniform or incoherent behaviors (for example it is difficult to modify the font used in the edition zone of a combo box, there are other examples...)
- let the developer set the event dispatching thread to ease the interoperability with SWT, JavaFX, etc...
- support CSS (like JavaFX)
- expose some parts of the API that handle the data manipulated by the GPU to ease the integration in existing 3D engines (Ardor3D, JMonkeyEngine, 3DzzD, Xith3D, Java3D, ...)
- modify PhoneME Advanced For Android to support a larger subset of JavaSE instead of relying only on a very poor subset of J2ME

Offline pjt33
« Reply #1 - Posted 2013-07-25 13:04:47 »

- try to remove some non uniform or incoherent behaviors
Inconsistent - it's a false friend.

The biggest design problem I had with Swing is its reliance on java.util.Vector and java.util.Hashtable rather than genericised List and Map.
Offline gouessej
« Reply #2 - Posted 2013-07-25 14:20:44 »

The biggest design problem I had with Swing is its reliance on java.util.Vector and java.util.Hashtable rather than genericised List and Map.
Where and how was it a problem? Can you elaborate please? Maybe in JTable and JList?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2013-07-25 14:38:27 »

Yes, that was a massive arse, not being able pass in Lists to Swing models.

I must have been one of the few people who actually liked Swing. It was/is by far and away the best cross-platform UI and codebase I've used. Just look how wretched Qt is. Using the GIMP makes me want to hurt random people afterwards.

Cas Smiley

Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2013-07-25 14:43:54 »

Otherwise... by Java 7, GPU acceleration was pretty good if you ask me. Some long-standing bugs could have done with dealing with. The lack of a pure Java HTML5+CSS3 component was its main downfall.

Cas Smiley

Offline SHC
« Reply #5 - Posted 2013-07-25 16:55:11 »

I'll

  -- Set native look and feel as default
  -- Add more layouts and
  -- Integrated gui designer like .net platform

Offline gouessej
« Reply #6 - Posted 2013-07-25 17:38:41 »

Yes, that was a massive arse, not being able pass in Lists to Swing models.
Yes javax.swing.DefaultComboBoxModel takes a Vector in input, or an array but then you have to convert your list to an array (by using List.toArray()).

  -- Set native look and feel as default
It makes sense if you don't want to annoy the end user and if you want your application to look like native ones.

  -- Add more layouts and
Why is it important for you?

  -- Integrated gui designer like .net platform
I know a very little bit .NET. Aren't you already happy with Matisse, WindowBuilder and Scene Builder?

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #7 - Posted 2013-07-25 17:48:17 »

As far as I'm concerned JavaFX is the new Swing and has all the bells and wistles you'd want from a modern GUI toolkit. No need to rewrite it again Smiley
It actually reminds me a lot of how Android works there.

Yes, that was a massive arse, not being able pass in Lists to Swing models.

A bit annoying, but it's a really minor issue imho. Those are just some default models where usually you'd implement your own models anyway.

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #8 - Posted 2013-07-25 18:11:35 »

Quote
emulate native look and feels instead of relying on native features

Why is that an issue? Personally I'd prefer it if it relies more on native features, rather than emulating a native look&feel.
That said, I sort of like the Metal look&feel. It's clean, fast, and easily 'themeable' (dunno if that's actually English Smiley).
But what I miss in Metal is that it doesn't follow certain native features, like system font sizes (which is an issue since displays are quickly getting more pixels/inch which can make Swing GUIs difficult to read because they don't follow the OS there).

Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #9 - Posted 2013-07-25 18:14:27 »

As far as I'm concerned JavaFX is the new Swing and has all the bells and wistles you'd want from a modern GUI toolkit. No need to rewrite it again Smiley

JavaFX doesn't have a date picker of any type, and it doesn't have a masked/formatted text field like swing. That's only two fields that I've wanted since I started using it 2 days ago. I'm sure there are many more!

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Andre Lopes
« Reply #10 - Posted 2013-07-25 18:36:11 »

As far as I'm concerned JavaFX is the new Swing and has all the bells and wistles you'd want from a modern GUI toolkit. No need to rewrite it again Smiley

JavaFX doesn't have a date picker of any type, and it doesn't have a masked/formatted text field like swing. That's only two fields that I've wanted since I started using it 2 days ago. I'm sure there are many more!

JavaFx is not ready. Thats why it still didnt replace swing.Yet.

But it will. Oracle said so.

Anyway, javafx > swing > AWT
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #11 - Posted 2013-07-25 18:48:39 »

As far as I'm concerned JavaFX is the new Swing and has all the bells and wistles you'd want from a modern GUI toolkit. No need to rewrite it again Smiley

JavaFX doesn't have a date picker of any type, and it doesn't have a masked/formatted text field like swing. That's only two fields that I've wanted since I started using it 2 days ago. I'm sure there are many more!

JavaFx is not ready. Thats why it still didnt replace swing.Yet.

But it will. Oracle said so.

Anyway, javafx > swing > AWT

True, some things are missing, but imho it's got the basics right.
In the meantime there are very usable 3rd party date-pickers and masked text fields (the latter is really easy to implement anyway).

Offline gouessej
« Reply #12 - Posted 2013-07-25 19:19:30 »

As far as I'm concerned JavaFX is the new Swing and has all the bells and wistles you'd want from a modern GUI toolkit. No need to rewrite it again Smiley
It actually reminds me a lot of how Android works there.
In my humble opinion, JavaFX has some really cool features but it has some design flaws that were already in Swing and Java3D.

At first, you cannot set the event dispatching thread. This is very problematic when you want to create fully realtime 2D GUIs mixing JavaFX and other UI APIs. When I start working on an existing software at work, I cannot suggest to rewrite everything from scratch. The use of bridges allows to use several UI APIs together but when you can't use the same thread to update the GUIs, one of the UI APIs have to be prioritized which means that the other ones will receive the events a bit later (this is not a problem in some cases). I already had this problem when mixing SWT and Swing.

Secondly, JavaFX high-performance hardware accelerated graphics pipeline has several backends like Java2D and Java3D <= 1.5 which are painful to maintain and produce inconsistent results across platforms. I have found a way to disable the Direct3D pipeline in Prism but if the OpenGL pipeline is badly maintained under Windows, it will be problematic when you must use OpenGL (you want to avoid conflicts at driver level).

Thirdly, as a consequence, it is very difficult to implement an efficient interoperability between JavaFX and existing OpenGL bindings.

Fourthly, according to some unconfirmed rumors, some parts of AWT are used in JavaFX. Anyway, Oracle has no plan to support JavaFX on mobiles whereas there are more and more opportunities under Android (and Dalvik VM is still significantly worse than JavaSE).

Quote
emulate native look and feels instead of relying on native features

Why is that an issue? Personally I'd prefer it if it relies more on native features, rather than emulating a native look&feel.
That said, I sort of like the Metal look&feel. It's clean, fast, and easily 'themeable' (dunno if that's actually English Smiley).
But what I miss in Metal is that it doesn't follow certain native features, like system font sizes (which is an issue since displays are quickly getting more pixels/inch which can make Swing GUIs difficult to read because they don't follow the OS there).
It complicates the port, it is harder to maintain (just look at all required efforts to keep 2 OpenGL bindings working under Mac OS X), if the support of native look and feels impacts the UI manager too deeply then you can get "standard" components behaving very differently under some platforms  Angry, it means that you cannot test the native look and feel of a given platform on a platform that doesn't natively support it. Sorry but I don't want to buy a Mac.

Offline gimbal

JGO Knight


Medals: 25



« Reply #13 - Posted 2013-07-25 20:58:45 »

Yes, that was a massive arse, not being able pass in Lists to Swing models.

I must have been one of the few people who actually liked Swing. It was/is by far and away the best cross-platform UI and codebase I've used. Just look how wretched Qt is. Using the GIMP makes me want to hurt random people afterwards.

Cas Smiley

Actually of all the GUI toolkits, I like Swing the most. Did plenty of tools with it, works like a charm and the custom painting isn't too bad to handle.

Its just really dated nowadays, although the specialized look & feels can also solve that. I was always very partial to substance for example.
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #14 - Posted 2013-07-25 21:07:12 »

Swing is an impressive API and nice apps can be written with it, but it is overly complex. Some complexity is necessary and some of the stuff Swing can do, especially the level of customization for some widgets, is very impressive. The rest is a bit of a mess. Swing has layer upon layer (eg, AWT), tracing events, layout, etc is hell. Part of the problem is that Sun refuses to do spring cleaning. Everything is always backwards compatible and over many years you end up with layers and layers of cruft. Things must be refactored and made nice so everything makes sense and fits together well, otherwise it doesn't.

Swing has poor layout support (just like almost every UI toolkit out there). For proper layout you need a scheme for validation/invalidation. Swing has this, but it is a bit weird. You also need *good* layout managers. Swing comes with a handful of crap layout managers (again, just like almost every UI toolkit out there, eg Android UI) that A) only do the job for simple demo apps, or 2) are too freaking complicated to actually be used (see GroupLayout). Yes, a proper layout manager can be written for Swing (eg tablelayout works with Swing) but the percentage of Swing users that will use a 3rd party layout is tiny, most struggle with GridBagLayout or hobble themselves with GridLayout and friends. Same on Android, tablelayout works there too but UIs are built with the horrible Android layout managers (made worse only by the inclusion of XML to design UIs, but that is a separate rant).

Skinning a Swing UI is nearly impossible. There are almost no docs and it is crazy complicated. I could never figure it out.

So to answer your question, I would build scene2d. Smiley I want my UI toolkit lightweight, easy to understand, easy to trace through, and easy to skin. scene2d has its warts for desktop UIs, eg focus traversal is lacking, but they are not insurmountable.

I don't think CSS is a good idea. The complexity explodes. Too many crazy features like that and you quickly have a monolithic UI toolkit that is hard to use.

Offline gouessej
« Reply #15 - Posted 2013-07-25 21:25:29 »

I find layout managers in Android a lot more crappier than in Swing.

Netbeans Platform is a very good solution based on Swing but a lot easier. I noticed some nice stuffs nsigma made with it in PraxisLive  Grin

Maybe supporting only a subset of CSS would be enough.

Offline SHC
« Reply #16 - Posted 2013-07-26 03:03:01 »


I like MigLayout well than the default ones. So I'll integrate it if I had rewritten swing.

  -- Integrated gui designer like .net platform
I know a very little bit .NET. Aren't you already happy with Matisse, WindowBuilder and Scene Builder?

I didn't use Matisse and Scene Builder but ones used the WindowBuilder. The provided window border became over some components in Ubuntu when tested. The window metrics are different across OS'es.

Offline SHC
« Reply #17 - Posted 2013-07-26 03:04:51 »

And one more

  -- I'll add HTML 5 support for
JEditorPane
's
HTMLEditorKit

Offline gouessej
« Reply #18 - Posted 2013-07-26 08:38:00 »

The provided window border became over some components in Ubuntu when tested. The window metrics are different across OS'es.
I didn't know that, thanks.

Offline pjt33
« Reply #19 - Posted 2013-07-26 14:13:45 »

I didn't use Matisse and Scene Builder but once used the WindowBuilder. The provided window border became over some components in Ubuntu when tested. The window metrics are different across OS'es.
Sounds like you weren't calling Window.pack(). "WYSIWYG" layout tools tend to generate bad code (which plays very badly with revision control systems). That's why some of us would much rather have good layout managers which let us express what we want in code than rely on GUI editors.
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #20 - Posted 2013-07-26 14:23:06 »

GUI editors may have worked ok back in the early 90s but these days you absolutely need programmatic layout managers doing the work properly. Swing could have done with a few more common layout managers such as a "FormLayout" and tweaks to existing managers to make them more flexible or easier to use.

Cas Smiley

Offline nsigma
« Reply #21 - Posted 2013-07-26 15:21:07 »

Netbeans Platform is a very good solution based on Swing but a lot easier. I noticed some nice stuffs nsigma made with it in PraxisLive  Grin

Hey!  Thanks for the mention - glad you like it.  Incidentally, all new (and first) website went live last week - www.praxislive.org

Maybe supporting only a subset of CSS would be enough.

The general appearance stuff, and possibly animation stuff, would be great. Probably not the layout stuff though - swapping one bad thing for another!  Wink  Still, we've just moved to using Compass / SASS for websites - using that on the above website was a joy compared to skinning the application itself!

Netbeans Platform is a very good solution based on Swing ...

To go back to your point about the NetBeans Platform, there is an interesting question there as to what happens with older, large-scale software if / when JavaFX takes centre stage.  Migrating any such large code base will not be an easy task - though it is possible to integrate JavaFX components into Swing, that's hardly ideal.  There have been a few interesting discussions about that on the platform mailing list.

I guess the key thing I'd look at doing if rewriting Swing would be to relook at the MVC aspects of it, and try and move as much as possible of the logic and model stuff outside of the UI toolkit entirely - make migration easier!!!

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #22 - Posted 2013-07-27 03:18:38 »

Everyone always complains about Layout managers in Swing. I have never had a problem getting it to do what I want. Is it more just the nesting required to get layouts to work that people don't like?

Offline gouessej
« Reply #23 - Posted 2013-07-27 15:04:38 »

Everyone always complains about Layout managers in Swing. I have never had a problem getting it to do what I want. Is it more just the nesting required to get layouts to work that people don't like?
I complain about layouts under Android but not about Swing layouts which are ok for me. SWT layouts are less reliable, I wasted a few days because of a very buggy class handling constraints in the table layout.

Hey!  Thanks for the mention - glad you like it.  Incidentally, all new (and first) website went live last week - www.praxislive.org
I just realize that your skills in Netbeans Platform are better than mine. I sometimes spend a lot of time in writing custom editors and custom in-place editors. I use a lot the property sheet.

The general appearance stuff, and possibly animation stuff, would be great. Probably not the layout stuff though - swapping one bad thing for another!  Wink  Still, we've just moved to using Compass / SASS for websites - using that on the above website was a joy compared to skinning the application itself!
Thank you, I will have to look at it.

To go back to your point about the NetBeans Platform, there is an interesting question there as to what happens with older, large-scale software if / when JavaFX takes centre stage.  Migrating any such large code base will not be an easy task - though it is possible to integrate JavaFX components into Swing, that's hardly ideal.  There have been a few interesting discussions about that on the platform mailing list.

I guess the key thing I'd look at doing if rewriting Swing would be to relook at the MVC aspects of it, and try and move as much as possible of the logic and model stuff outside of the UI toolkit entirely - make migration easier!!!

This is a very important aspect. I would like to know how Netbeans Platform will evolve on the long term. Yes the view and the controller seem tightly bound in Swing. Netbeans Platform follows the design pattern DCI, it's a bit better than M on one side and VC on the other side.

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #24 - Posted 2013-07-27 21:14:34 »

Quote
I find layout managers in Android a lot more crappier than in Swing.
Well, I have to admit that there are an awful lot of 'gotchas' in Android layouts. In Swing, these things are a lot more predictable and easy to use.

Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #25 - Posted 2013-07-27 22:05:08 »

Everyone always complains about Layout managers in Swing. I have never had a problem getting it to do what I want. Is it more just the nesting required to get layouts to work that people don't like?
It's the lack of flexibility. Often a grid is fine, but rarely do you want the cells the same size. Often you need a few extra pixels between something and this flexibility just isn't possible without using GridBagLayout, which has the usability of a turd. That video is so spot on, it's sad. GroupLayout is a nightmare, it isn't how people naturally think about layouts. FormLayout I'm not very familiar with, but using tables is the WTG IMHO, so they got that right. It uses a DSL for column and row constraints which is unintuitive and moves layout data away from where the widget is added to the layout, which hurts readability a lot. Also specifying column and row for each widget is awkward. MigLayout is a complicated beast that IMO tries to do too much and also has an unintuitive DSL. A DSL also leads to string concatenation when you have dynamic values, which is nasty.

Back to the point, most Swing layouts suck, even 3rd party ones. I'm not saying you can't build apps with them, I'm just saying it is unpleasant. Not to single out Swing, the same is true for most (all?) UI toolkits. Obviously I'm biased by my baby, tablelayout but once you learn the constraints (there are only 7, only about 3 of which you most often need) then laying out almost anything via code is easy, and the resulting code is easy to read. You can quickly build a mental model of the layout so you know how to modify it to get what you want.

There is one other 3rd party Swing layout that I think is neat, DesignGridLayout. It uses canonical grids for layout. The example code mostly just adds widgets to the layout and that is all. It's amazing what it can do without any constraints! The downside is that you can't tweak it to meet your needs, you are SOL if you need a little extra space or in fact anything that is not a canonical grid. I prefer a single layout manager that is easy to use and enables most layouts.

Offline davedes
« Reply #26 - Posted 2013-07-27 22:07:42 »

Swing does a pretty good job at emulating the platform's look and feel, except for JFileChooser. Especially on OSX. In my own apps, I'm now relying on FileDialog for OSX since it isn't complete crap.

Swing is not a bad framework given its scope and complexity. Java2D is also great for what it aims to do -- cross-platform and consistent raster graphics for UI and simple visual apps. But neither platform is very "future proof" in today's world of mobile phones and tablets, hardware rendering, Google Glass, Oculus Rifts, Leap Motions, and so forth.

P.S. I recently used Nate's TableLayout in a Swing app, it's way nicer to work with than the default layouts. Smiley

Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #27 - Posted 2013-07-27 22:44:01 »

As far as I can tell all Swing layout problems were solved by SpringLayout.

Cas Smiley

Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #28 - Posted 2013-07-27 23:34:35 »

@davedes, awesome! Cheesy

@princec, nah, SpringLayout sucks too. You can't look at the code and get a meaningful idea of what the layout is going to look like. IMHO, people don't think about layout by what edge of something is attached to something else's edge. They think about tables. Table tables tables, all the way down.

Offline Cero
« Reply #29 - Posted 2013-07-28 00:42:32 »

scene2d ui should support CSS  :D

Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (39 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (36 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!