Why Swing / JavaFX is not a platform (yet)
If a platform is a set of resources (both code and data) which can be organized to create an application, then the usefulness of a given platform is defined by the utility and consistent availability of these resources. It is my belief (and has been for 10 years now) that Swing and JavaFX could both go much further in terms of adoption if the Java platform had built-in font support.
The reason is simple: native fonts are unreliable. A given font may or may not exist and may or may not render the same image on two operating systems running your supposedly portable Java application. This inconsistent availability and appearance of fonts is the root problem which forces the use of layout managers in cases where users simply want to place components at pixel-precise locations and have them stay put (in fact, this is arguably the use case most of the time!).
It is not actually Java coding, but layout managers which have been holding desktop Java back all these years. And without fixing the root problem here, JavaFX will just inherit the same issue with the same rather predictable result. If you don’t believe me that layout managers are a problem, take a look at the JavaFXPad WebStart example. Even the people making JavaFX have a difficult time getting layout managers to make things look nice:

While it is technically true that you can embed fonts in your Java applications, I think this is a cop-out which just skirts the core issue that JavaFX is not a real and reliable platform without the consistent availability of font resources. I mean, think about this. What would Windows be like if every application had to license and embed its own fonts? How well would that work?
Now imagine what Java Web Start and JavaFX would be like if the underlying Java platform included access to reliable, pixel-accurate, pure Java fonts.
- Login or register to post comments
- 2532 reads
- Flag as offensive
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)







Comments
Mikael Grev replied on Thu, 2008/05/15 - 5:50am
For some reason the Swing engineers are not interested in solving the problem with layout managers. The sad fact is even that JavaFX will just wrap the old very limited layout managers. I thought that when they are in fact creating a new API, why not solve this and be done with it?
I had a session at JavaOne about MiG layout and got a lot of positive feedback. Adding MiG layout to the platform is climbing fast on the Top 25 Request for Enhancement list at Sun (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6530906). That RFE system is the only way we have to put preassure on Sun and they constantly tell us to "file a RFE". The problem is only that they still just choose the RFEs they like and not the RFEs people like, or so it seems.
The normal answer I get from Sun people is that "Well, it is an excellent Layout Manager, but wouldn't it be better to have it outside the JDK so that users can download it?". The problem is that only about 1% (guesimated) actually will go out on the net and find a replacement, so that argument really doesn't matter.
If users complain about Layout Managers being crap in Swing, then that is a fact. Sun might think that the commenters are at fault for thinking so but that does not change the fact that they DO think so. And developers outside Sun are not more stupid. Infact they are probably using the APIs more than Sun developers, which are creating them.
Everything (almost) developers complain about has after a while ended up being fixed and I salute Sun for this. The problem is that it takes way too long and they resist furiously until they finally understand.
If there is a problem it should be solved IMO. The only way to know what is wrong is listening to the users, and I mean actually listening. Hearing what we say and disregard it will only increase tention.
Btw, the ugly fonts will finally be solved. Java 6u10 has native font rendering... After 7 years of complaining it finally paid off...
Fabrizio Giudici replied on Thu, 2008/05/15 - 6:05am
Mikael Grev replied on Thu, 2008/05/15 - 7:08am
in response to: fabriziogiudici
Carl Antaki replied on Thu, 2008/05/15 - 7:35am
Fabrizio Giudici replied on Thu, 2008/05/15 - 8:55am
Carl Antaki replied on Thu, 2008/05/15 - 9:03am
Fabrizio Giudici replied on Thu, 2008/05/15 - 9:11am
Jonathan replied on Thu, 2008/05/15 - 9:49am
I wouldn't say Java's layout managers are a complete failure Fabrizio, but this video sums up my thoughts :)
http://madbean.com/anim/totallygridbag/
I use MigLayout for just about everything. Complex panels, simple panels, cell renderers, everything. The behavior is very predictable and it just does what I expect it to.
Fabrizio Giudici replied on Thu, 2008/05/15 - 9:56am
Osvaldo Doederlein replied on Thu, 2008/05/15 - 12:59pm
JeffS replied on Thu, 2008/05/15 - 1:07pm
in response to: opinali
As of Java 6, where it defaults to anti-aliased fonts (finally!), I've had zero problems with fonts in Java, whether running on Windows or Linux.
That said, it wouldn't hurt for Java to have it's own rich set of fonts (that are anti-aliased, of course).
Also, the ongoing improvement of layout managers is a good thing. But I do quite like Matisse. Except in rare cases, it's the way to go. It's as easy as pie to get a great looking interface that has stuff lined up how you want them.
Jim Weaver replied on Thu, 2008/05/15 - 1:21pm
Mikael Grev replied on Thu, 2008/05/15 - 1:37pm
in response to: carcour
Mikael Grev replied on Thu, 2008/05/15 - 1:38pm
in response to: jlweaver
Fabrizio Giudici replied on Thu, 2008/05/15 - 1:43pm
in response to: opinali
Osvaldo Doederlein replied on Thu, 2008/05/15 - 2:55pm
Yes, the Java fonts and renderer should be kept as a backwards compatibility option, perhaps forever. They could just be off by default, and for JavaKernel, downloaded as a last priority bundle or only at first need.
Apple's Sun/Quartz pipeline change is a different issue that we discussed before... btw, any changes in the FCS of Apple's Java6?
Dmitri Trembovetski replied on Thu, 2008/05/15 - 4:20pm
in response to: opinali
> any changes in the FCS of Apple's Java6?
It's been released a couple of weeks ago. Only for Intel and 64-bit only, unfortunately.
Osvaldo Doederlein replied on Thu, 2008/05/15 - 8:15pm
in response to: tdv
> any changes in the FCS of Apple's Java6?
It's been released a couple of weeks ago. Only for Intel and 64-bit only, unfortunately.
I know, I meant - does this version use the Quartz pipeline?
Jonathan Locke replied on Thu, 2008/05/15 - 11:02pm
I'm not necessarily opposed to native font rendering (although over the long term I would expect Java font rendering to be a better way to go), but any kind of font rendering in Java should look almost exactly identical on any two platforms (which means Java must include a full suite of fonts like Windows does) and absolutely must result in precisely the same bounding box for a given piece of text.
There are other reasons to use layout managers to be sure (for example, localization, pluggable look and feel or stretchable dialogs), but for an overwhelming number of applications, they simply are not necessary if the sizes of components can be fixed by a designer. And fixed size components are not reliably possible without fixed sized text.
Although swing has greater generality in terms of look and feel, I think many applications would be better written in a single, fixed, simple style (like the metal look and feel, only slicker). The complexity created by pluggable look and feel is really not worth it much of the time. What's more, the market for Java FX is going to be online applets more than desktop applications, and that audience is really only going to be interested in precise designs.
I would not suggest that layout managers are undesirable or that they have not improved, but they have never been a good default for the vast majority of users and particularly designers, who often have simple fixed problems and want a precise look and feel. Even with the new group layout and Matisse, I still finding layout managers pretty frustrating and sloppy and they make input from professional designers much more difficult. If there are easier options on other platforms, users will choose them.
Fred Swartz replied on Fri, 2008/05/16 - 4:07am
Unfortunately it's not an exaggeration to say that the Sun's layout managers have been a complete disaster.
There are many examples of good (non-Sun) layout managers, MIG layout being the most recent, which are simple to use and produce a very attractive result.
GroupLayout can produce good results, but is effectively completely dependent on Matisse, which is an unattractive choice for many.
The fact that Sun's examples either look like crap or are almost impossible to refactor by hand (ie, GridBagLayout, GroupLayout), that students (and textbook authors!) can't produce a nice GUI, and that the best advice you can give someone is to use a non-Sun layout manager seems to be adequate evidence of the disaster.
Karsten Lentzsch replied on Fri, 2008/05/16 - 4:44am
in response to: mgrev
I'm surprised about that statement. In layout courses I found that the contrary is the case. Every Java developer I met could work with DLU.
Logical pixels work quite well on a single platform with a single main control font. Logical pixels suck, if you change platforms or move over to different fonts. MS provides these nasty tables for folks that move layouts over from Tahoma to Segoe UI. That's basically what you face if you deploy an app on multiple platforms - which is at the core of many Java UIs.
Mikael Grev replied on Fri, 2008/05/16 - 4:53am
in response to: kl33281
Hello Karsten,
I am sure everybody can easily be taught how to use DLUs, they are simple to understand. The problem is to get people to use them. Not many developers actually have attended a GUI creation course, where DLUs are used. How many Java developers do you think actually create GUIs using DLUs today? 1%?
Logical Pixels are exactly the same as DLUs. It is just a factor thereof to make 1 pixel mean 1 lp on a standard screen. This means that as long as people just use the default unit (e.g. "width 100" and not "width 100px") they will get resolution independence for free.
Logical pixels even has two modes in MiG Layout. Font based and actual screen DPI based. The knowledgeable user can actually make the choise. I prefer to have it scale to the DPI of the screen since that is decoupled from the Font and more intuitive to understand.
cfagan replied on Fri, 2008/05/16 - 7:27am
in response to: jonathanlocke
If someone wanted to they could use Null Layout. Then package up some free fonts (like Bitstream) with the program and force the font sizes in the Look and Feel. Given that type of environment I'm sure one can build a wonderfully designed interface for one specific set of circumstances. The problem is that users do not fit into one set of circumstances. Internationalization, accessibility for the disabled, high DPI screens, and even resizeable windows are all things that you can't use exact pixel placement to design for. We all know what people did before layout managers. They hard coded pixel locations and made windows that don't resize. So now we are left with a task that requires a balance of programming skills and design skills. Not everyone has both.
Maybe I'm wrong. There are plenty of web sites that have hard coded pixel sizes. There are plenty that are not internationalized or respond poorly to larger fonts. Why should Java be any different? Is there any platform that "gets is right" that we could learn from?
Fabrizio Giudici replied on Fri, 2008/05/16 - 7:27am
in response to: jonathanlocke
any kind of font rendering in Java should look almost exactly identical on any two platforms ...
but for an overwhelming number of applications, they simply are not necessary if the sizes of components can be fixed by a designer ...
Although swing has greater generality in terms of look and feel, I think many applications would be better written in a single, fixed, simple style (like the metal look and feel, only slicker).
The three above statements have a logical link, so I'm quoting all of them. Well, I strongly disagree :-) You can't just ship a Swing application to Mac users if it carries "a slicker" metal look and feel. Unless you have reasons for developing your own look and feel, Mac users want Aqua. They are so picky that most of them can immediately spot even minor disturbances of the Apple's HIG, such spacing with the wrong number of pixels. This invalidates all the three above sentences: since on Mac OS X you must have the specific margins, spacings and the fonts must look like the fonts in native Mac OS X applications. Hence you can't avoid layout managers.
Of course one could say that wants only to develop for Windows or Linux...
Jakub B?aszczyk replied on Fri, 2008/05/16 - 9:21am
Have a look at SWT/JFace layout managers that Eclipse RCP uses. It is commonly admitted that Eclipse looks great. There are some ports of SWT's layout managers to Swing, especially FormLayout.
Building forms with fixed-position was something Visual Basic and Borland Delphi were based on. But up until now even MS is dropping that approach I guess.
The reason to use layout managers is not only portability, but more importantly use of custom fonts. Windows or Linux user may use a desktop theme which is based on, say, big fonts, or a disabled person might want use such fonts to ease work with his PC. Just image a font beight slightly larger than deafult buttons height! "Cancel" could not fit within a button!
Jonathan Locke replied on Fri, 2008/05/16 - 10:46am
You can't just ship a Swing application to Mac users if it carries "a slicker" metal look and feel.
Totally disagree. That's what most of this RIA stuff is... custom UI LAF.
Fabrizio Giudici replied on Fri, 2008/05/16 - 1:53pm
Jonathan Locke replied on Sat, 2008/05/17 - 6:39pm
Jonathan Locke replied on Sat, 2008/05/17 - 6:42pm
Mikael Grev replied on Sat, 2008/05/17 - 7:24pm
in response to: jonathanlocke
What is a Layout Manager though? Unless you go 100% with null layout and position everything by x and y in pixels you are using a Layout Manger, even if you don't call it that. One that can only position the right edge of a compoent to the container's edge is still layout manager...
What you are saying is that the layout managers you have encountered in Java is crap, right? Or?