Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
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]
  ignore  |  Print  
  Arrrrrgh, Swing!  (Read 3113 times)
0 Members and 1 Guest are viewing this topic.
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Posted 2004-12-20 20:06:04 »

Why is everything so blooming hard to get right in Swing?

Why are there no decent layout managers?   I used to think GridBagLayout was the biggest and best, but its mysterious rules about component widths (that Sun seem reluctant to explain) just mean it's a pig to work with.  Why, when CSS gets everything done in one place, do we have any more layout managers than one?

Why is there no feedback about why something is behaving in a certain way?  I refuse to accept that the core API is developed without any logging at all - that would just be stupid - and suspect it's conditionally-compiled out of each release.  Why can't I get hold of a debug-enabled build?

Why do seemingly trivial settings cause massive changes throughout the GUI?  Why do I have to dig into the API source to discover why turning on line wrapping on a JTextArea causes fundamental changes in component layout?

Why does there seem to be no consistency in component layout?  Why are there funny little border cases all over the place where moving something 1 pixel to the left causes the layout to change by 200 pixels, or more?

Why is the Swing documentation so poorly maintained?  Why is the Java Tutorial positively littered with [PENDING] comments?

Why did Sun even bother with HTML support?  Things were added with no attempt to make them appropiate for a GUI, and I've never managed to find any useful documentation on any of it.  It's almost as if it were included for the sole purpose of being buzzword-compliant.

Why does it often seem like half the API is missing?  Given the existence of layout managers that ignore e.g. heights, why am I forced into providing a (dummy) height when I want to set a minimum width - where's the setMinimumWidth() method?

Edit: And why oh why oh why does it seem like nothing respects minimum/maximum/preferred sizes?  Is it really too much to ask to have a text box with arbitrary text in it that stays at the size I set it to?


Is it just Swing... or are all GUI toolkits this bad? :-/

Hellomynameis Charlie Dobbie.
Offline Virum

Junior Member




Like a leaf in an icy world, memories will fade


« Reply #1 - Posted 2004-12-21 02:32:31 »

You aren't the only one. Sad

Have you thought about giving SWT (I think) a try?  Eclipse "uses" it for its GUI; it seems nice enough.

It's time to prove to your friends that your worth a damn. Sometimes that means dying; sometimes that means killing a whole lotta people.

Blog
Offline JasonB

Junior Member





« Reply #2 - Posted 2004-12-21 03:38:09 »

Quote

Is it just Swing... or are all GUI toolkits this bad? :-/

I recently wrote (well half-wrote, haven't quite finished it yet) a text editor in python+gtk.  To be honest, I preferred it to Swing, but I don't think it was particularly straight-forward either.
In my experience, GUI toolkits seems to inhabit a black or white space (i.e. very few shades of grey). They're either simple to use, and therefore a bleedin nightmare when you want to do something complicated; or complicated as hell, and end up giving you just enough rope to hang yourself...  Wink
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 2004-12-21 08:17:07 »

SWT's just as shit.

Cas Smiley

Offline Virum

Junior Member




Like a leaf in an icy world, memories will fade


« Reply #4 - Posted 2004-12-21 14:12:34 »

Quote
SWT's just as shit.

Cas Smiley



That's too bad to hear. Sad  Thanks for saving me the trouble of trying it. Wink

It's time to prove to your friends that your worth a damn. Sometimes that means dying; sometimes that means killing a whole lotta people.

Blog
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #5 - Posted 2004-12-21 16:50:08 »

Well, damn.  I might just move into goat-herding instead.

Hellomynameis Charlie Dobbie.
Offline Grazer

Junior Member




My other avatar is much more flattering.


« Reply #6 - Posted 2004-12-23 10:10:00 »

When developing swing apps, I don't start until I've included the following libraries.
If Swing is the toolkit, these are my power tools.  Cool
They don't remove all the woes, but they make a lot of things a lot easier.

Disclaimer:
The first two libraries are written by a work colleague of mine.
I do use them, and they are really good, otherwise I wouldn't recommend them.
The last library is my own creation.
Neither he nor I get any money from any of them.


Layout: Explicit Table Builder
Awesome "builder" (i.e. facade) over Explicit Layout that makes building layouts on a table structure (which covers pretty much anything that's designed correctly) really easy.

Action Logic: GUI Commands
An extension of Swing's "Actions" that makes the concept useful. Basically, you write your business logic in a Command, and then ask that command for a component (e.g. button, menu item, whatever) that connects to the command. Sounds weird, but once you use it, it makes a whole lot more sense than having anonymous ActionListeners all over the place.

Look & Feel: JGoodies Looks
Really good looking Multi-Platform L&F. Also has a really accurate (supposedly) Windows L&F emulation. (I use the multi-platform 'Plastic' look).

Threading: Foxtrot
Lets you execute time-expensive code from the Swing Event Thread while allowing other events on the Event Queue to keep pumping. Just brilliant. Have a look at the examples if you don't understand.

Logging: Simple Log
18K logging library that's really simple to use and works with essentially no configuration. Lots of features, though.

Current Project: Easy Decal
Other Stuff: grlea online
Offline zingbat

Senior Member




Java games rock!


« Reply #7 - Posted 2004-12-27 17:56:18 »

Swing is huge and slow and not very flexible. I wonder why they call it Swing at all. It should have been called Fat Joe instead.
Offline Grazer

Junior Member




My other avatar is much more flattering.


« Reply #8 - Posted 2004-12-29 06:57:20 »

Quote
Swing is huge and slow and not very flexible.

That's a pretty derogatory claim to make without any justification.
I'd like to hear why you think this.
For what it's worth, here's why I don't agree with your sentiment...

Yes, Swing is quite large.
It is a large API, has a not-small memory footprint, and can take a while to load when an app first uses it.
However, Sun is working to reduce these problems with every release, and the improvements are noticeable.

Swing is not slow.
Many people have this impression because their limited Swing experience is with poorly-written applications that don't know how to use Swing.
In analog, if I pushed a Ferrari around a race track, that wouldn't make the Ferrari slow. It would make me naive.
It is easy to make a slow Swing application when you know nothing about its threading model.
When you actually know what you're doing, you can write fast, responsive, professional-quality applications on top of swing.
Commercial example: IntelliJ.
There are hundreds more examples of Swing being used in commercial production environments at Swing Sightings.
It wouldn't be being used for real applications if it really was slow.

Lastly, Swing is flexible.
It is extremely flexible!
I can't think of a reason why someone would think it wasn't flexible, so I can't really argue against the point.
But, in terms of flexibility, it is both customisable and extendable.
i.e. there are many places where you can change the specifics of how a Swing component works and, if you need something really different, it's pretty straight-forward to roll your own.
That's one of the very reasons that it's "huge", and also why many people find it complex when they start working with it.
As for me, I've always found a way to do what I want to do.
Sometimes it takes a bit of digging in the API, and understanding some aspect of Swing that I was previously oblivious to, but there's always been a way.

As I said at the top, I really would like to hear why you have the impression of Swing that you have, but my experience of real Swing applications is counter to your claims.

Current Project: Easy Decal
Other Stuff: grlea online
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #9 - Posted 2004-12-29 09:35:07 »

One particular gripe I have with Swing is just how easy it is to write shit, slow code with it. And just how complicated and difficult it is to get just basic things looking right (not working right - that part's easy).


Cas Smiley

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

Senior Member




Java games rock!


« Reply #10 - Posted 2004-12-29 17:17:52 »

I used Swing in one or two school projects of average complexity and spent some time working out bugs that weren't documented in the javadocs. That was 1.4 so i don't know if anything has changed in 1.5.

Just to give you some examples the best choice you have to layout components is GridBagLayout. To do the same thing you do with that layout you need to use other layouts like BorderLayout and BoxLayout and stack panels together in a very bodersome and memory consuming way. One problem i had was that GridBagLayout doesn't update Swing components properly. There is a layout that looks very good: its called SpringLayout or something like it, but every documentation on it is cryptic at minimum.

Another problem is the lack of documentation many areas that would be great to use like the HTML kit or the view objects. At the time i consulted the 1.4 documentation there were many places with entire methods and classes completely undocumented. Maybe this happens because classes are not reused much. Swing tree components use their own tree implementation and views use their own graph structure instead of using the container classes in java.util. This is bad use of the java object model.

Besides that the thing that bothers me most is the amount the memory consuption of Swing components. If you look at other gui solutions Swing guis consumes an absurd amount of memory that cannot be justified.

Yes i know that experts in Swing can do very fast and very good apps in Swing. You have Magicdraw UML as an example of it.

The point is Swing is just too much trouble for just  a simple gui, with all its omissive documentation, performance misteries. Its looks like Sun hired amateur ex c++ programmers to do it. There are books as big as an encyclopedia just to teach people how to work with Swing. This is bad for a gui api.

If you want my advice stay away from it. Sooner or latter there will be more complete guis based on one of the opengl bindings that will be much faster, economical and esy to use than Swing.
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #11 - Posted 2004-12-29 19:11:24 »

Most of Swing's memory consumption is actually down to that daft huge double buffer. It's not all that inefficient when it comes to memory otherwise.

The documentation is pretty bad.

There aren't many useful shortcuts for the "90% of common cases" GUIs.

Cas Smiley

Offline zingbat

Senior Member




Java games rock!


« Reply #12 - Posted 2004-12-29 21:49:29 »

I think that what people apreciate on Swing is how Sun created a gui that is very good following HCI (Human Computer Interaction) usability and accessibility principles.

The design principles for the java look and feel are almost Mac quality.

http://java.sun.com/products/jlf/ed2/book/

Its just a shame that all of this is wasted in a rather poor implementation.
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #13 - Posted 2004-12-30 08:55:26 »

The more I look at Java's development over the years, the more I realise how fantastically underfunded and understaffed it is. To have taken this long to get to what 1.5 is, is just incredible.

Cas Smiley

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #14 - Posted 2004-12-30 09:51:48 »

Quote

That's a pretty derogatory claim to make without any justification.


Yup. You're right that for most things it's fast, and there's no *good* reason why any of it shoudl
be slow, but... it's also got slow crap bits.

Quote

Lastly, Swing is flexible.
It is extremely flexible!
I can't think of a reason why someone would think it wasn't flexible, so I can't really argue against the point.


Here's a good reason: Sun STILL HAVEN'T DOCUMENTED THE F***ING APIS THAT LET YOU EXTEND AND ALTER IT!!!

Try finding documentation on L&F's. There isn't any. Everyone's trying to reverse-engineer it from a JavaOne presentation a few years ago and from hacking on the java source.

(nb: this might, possibly, have changed inthe last 4-6 months. I very very much doubt it).

/me wonders why Swing has a bad rep...

malloc will be first against the wall when the revolution comes...
Offline Chman

Junior Member




Nothing more that... Java games are cool !


« Reply #15 - Posted 2004-12-30 12:49:05 »

Quote

Try finding documentation on L&F's. There isn't any.

And this ?
Offline Mark Thornton

Senior Member





« Reply #16 - Posted 2004-12-30 13:01:26 »

Quote

And this ?


Nobody reads design guidelines ... so perhaps the title ought to be changed.
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #17 - Posted 2004-12-30 13:58:42 »

Quote
Layout: Explicit Table Builder
Awesome "builder" (i.e. facade) over Explicit Layout that makes building layouts on a table structure (which covers pretty much anything that's designed correctly) really easy.

Action Logic: GUI Commands
An extension of Swing's "Actions" that makes the concept useful. Basically, you write your business logic in a Command, and then ask that command for a component (e.g. button, menu item, whatever) that connects to the command. Sounds weird, but once you use it, it makes a whole lot more sense than having anonymous ActionListeners all over the place.

Look & Feel: JGoodies Looks
Really good looking Multi-Platform L&F. Also has a really accurate (supposedly) Windows L&F emulation. (I use the multi-platform 'Plastic' look).

Threading: Foxtrot
Lets you execute time-expensive code from the Swing Event Thread while allowing other events on the Event Queue to keep pumping. Just brilliant. Have a look at the examples if you don't understand.

Logging: Simple Log
18K logging library that's really simple to use and works with essentially no configuration. Lots of features, though.


Interesting stuff!  I'll be looking further into these libraries for version two of my project - right now I just need things to work, they can work properly later.

The most recent class I've added to my project is a layout manager that only handles two objects: it gives 25% of the space to one, and 75% to the other.  It's bloody simple, and has solved all my layout problems.  I'm absolutely amazed that I couldn't shoehorn any of the current layout managers into performing this trivial task.  Ho-hum.

Dynamically-calculated minimum/preferred/maximum component sizes are a really good idea for a static GUI.  The moment you want to change the properties of a component at run-time, it becomes an absolute nightmare.

Quote
And this ?


I've read the look and feel design guidelines many times, and think they are very insightful on HCI matters.  Not at all helpful when you try and write an application using Swing, but great for designing the interface.

It's a damn shame that Sun have changed the default Metal theme in Java 1.5, violating many of the rules they themselves laid down when they wrote those guidelines.  Just because Microsoft promote a Fisher-Price GUI, doesn't mean chunky colourful widgets are at all a good idea.

Hellomynameis Charlie Dobbie.
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #18 - Posted 2004-12-30 15:57:24 »

Why won't they just buy the Alloy L&F???

Cas Smiley

Offline Chman

Junior Member




Nothing more that... Java games are cool !


« Reply #19 - Posted 2004-12-30 17:18:49 »

Quote
Why won't they just buy the Alloy L&F???

Cas Smiley



Dunno, but I must say that this one is impressive... I love it !

Chman
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #20 - Posted 2004-12-31 14:01:48 »

Quote

And this ?


That's not documentation. It's a marketing document to prepare interested parties before the product is ready.

It's ridiculous to offer it as LaF docs, since it has only ONE PARAGRAPH and a 3-way circular link in the glossary. It also has a very short appendix explaining how to switch the current LaF. Wow!

To recap: 0.000 documentation covering Swing LaFs. Except how to select one at runtime (and even that is incomplete!)

malloc will be first against the wall when the revolution comes...
kul_th_las
Guest
« Reply #21 - Posted 2005-01-12 12:45:21 »

I recently bought a book to help me with my Swing woes, "Swing 2nd Edition". It's good and bad...there are a number of typos, unfortunately, and the index is total crap - but even with these things it explains so much better the fundamental concepts of Swing. I've been through the Java Tutorial on Swing, I own the "Core Java Volume 2: Advanced Features" for 1.2, 1.3, and 1.4 - none of which were particularly helpful when developing a Swing app that wasn't directly copied from the book.

I highly recommend this book, but if I were you guys I might wait and hope for "Swing 3rd Edition" - but honestly, it's cleared up so many little misunderstandings that I had about Swing from all the other so-called documentation - it was the light at the end of a 4 year tunnel, I tell you.
Offline Grazer

Junior Member




My other avatar is much more flattering.


« Reply #22 - Posted 2005-01-13 22:15:18 »

Some more resources for anyone still reading this thread, these presentations are great.

For people who think Swing is slow:
"Professional Swing: Threading"

For people with other Swing gripes (L&F, ease-of-use):
"Professional Swing: Creating Polished Applications"

Current Project: Easy Decal
Other Stuff: grlea online
Offline nikster

Junior Newbie




Java games rock!


« Reply #23 - Posted 2005-01-14 11:54:50 »

Quote

Layout: Explicit Table Builder
Awesome "builder" (i.e. facade) over Explicit Layout that makes building layouts on a table structure (which covers pretty much anything that's designed correctly) really easy.

Action Logic: GUI Commands
An extension of Swing's "Actions" that makes the concept useful. Basically, you write your business logic in a Command, and then ask that command for a component (e.g. button, menu item, whatever) that connects to the command. Sounds weird, but once you use it, it makes a whole lot more sense than having anonymous ActionListeners all over the place.

Look & Feel: JGoodies Looks
Really good looking Multi-Platform L&F. Also has a really accurate (supposedly) Windows L&F emulation. (I use the multi-platform 'Plastic' look).

Threading: Foxtrot
Lets you execute time-expensive code from the Swing Event Thread while allowing other events on the Event Queue to keep pumping. Just brilliant. Have a look at the examples if you don't understand.

Logging: Simple Log
18K logging library that's really simple to use and works with essentially no configuration. Lots of features, though.


the above should be on the very first page in the Swing tutorials. would save everyone lots of trouble. thanks for this!

ad Swing in general:
- The biggest problem i have with Swing is that all the defaults are wrong, for example in GridBagLayout. what you want most is _not_ the default. I resorted to writing my own util classes to help with getting GBL to work nicely. nevertheless, it's a PITA. (ad: first poster, what you want to do in GBL works, you just need to know how)
- Another issue is that there isn't just one way to do something. Usually, you can achieve the same result in a zillion different ways. Many of which are subtly wrong. That means only one thing: Badly designed framework.
- There are no guidelines on how to do things. Sun doesn't tell you, for example, how to use ActionListeners. Do whatever you want.
- The above holds true for Swing itself too. If you look at the source code, it's a huge mess, where everybody does whatever they think they want to do. No conventions, messy code, outright stupid mistakes, lots of static state-keeping fields... There were no coding guidelines or if there were, they were not enforced...
- No native L&F. How hard would it be for Sun to just use the Windows L&F that is installed on the system? Then Java apps would just look like any other app, even after installing SP-whatever. Emulating this with their own bitmaps is just silly. Take SWT as an example in this regard. The app looks just way more professional.

[/rant]

I know about threading and these things (and Foxtrot! Yey!) so speed isn't an issue. In fact, Swing is damn fast. I am timing my app and creating even very complex layouts with images and stuff takes usually in the range of 30ms. That's FPS-ready response time. Swing is a lot of things, but it is not slow.
Offline Mark Thornton

Senior Member





« Reply #24 - Posted 2005-01-14 13:18:23 »

Quote
The most recent class I've added to my project is a layout manager that only handles two objects: it gives 25% of the space to one, and 75% to the other.  It's bloody simple, and has solved all my layout problems.  I'm absolutely amazed that I couldn't shoehorn any of the current layout managers into performing this trivial task.  Ho-hum.

In 1.5 (5.0) you can do that with SpringLayout. Previously SpringLayout was rather incomplete. However SpringLayout is intended to be used by gui builders and not directly via hand coding.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #25 - Posted 2005-01-14 13:47:04 »

Quote


The most recent class I've added to my project is a layout manager that only handles two objects: it gives 25% of the space to one, and 75% to the other.  It's bloody simple, and has solved all my layout problems.  I'm absolutely amazed that I couldn't shoehorn any of the current layout managers into performing this trivial task.  Ho-hum.


I did something similar, but with more options and a sprinkling of cleverness. I have been threatening to tidy it up, document it, and put it online for free for...oh, about 8 months now. Whoops.

Hopefully I'll get around to it once JGFv3 is live. That thing is now a great big monster clinging to my back, weighing me down Sad.

malloc will be first against the wall when the revolution comes...
Pages: [1]
  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 (33 views)
2014-08-22 19:31:30

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

Tekkerue (40 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 (37 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!