aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Default font is bigger on Mac/Linux than Windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Default font is bigger on Mac/Linux than Windows" Watch "Default font is bigger on Mac/Linux than Windows" New topic
Author

Default font is bigger on Mac/Linux than Windows

Thomas Kiersted
Greenhorn

Joined: Feb 24, 2007
Posts: 22

I've been programming what I hope to be a cross-platform Swing application on Windows XP, and when testing on Mac/Linux, I've noticed that the GUI doesn't quite line up, regardless of layout, and despite using the same Metal look and feel on all platforms. The crux of the problem is that the fonts on Mac/Linux take up more horizontal space by approximately 10%, pushing everything further over, and causing my components to run off the edge of the window (as well as causing visibility problems in some panels).

So my suspicion is that the default font for Java is different on Windows than on Mac/Linux. However, I'm not sure quite how to fix this problem. According to NetBeans, the font I'm using is called "Dialog". Does anyone know a way to get the same font width on Mac as Windows?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
You shouldn't expect Swing GUIs to be identical pixel-by-pixel across platforms. That means using absolute sizes (in pixels) doesn't work. But if you call "pack()" after layout the components, then none should be invisible, provided the top-level container is large enough.


Ping & DNS - my free Android networking tools app
Thomas Kiersted
Greenhorn

Joined: Feb 24, 2007
Posts: 22

Ulf Dittmer wrote:You shouldn't expect Swing GUIs to be identical pixel-by-pixel across platforms. That means using absolute sizes (in pixels) doesn't work. But if you call "pack()" after layout the components, then none should be invisible, provided the top-level container is large enough.


I have a call on pack(). I suppose this means, though, that it isn't possible to guarantee that the top-level container will fit on a 1024x768 screen? I'd like to be able to guarantee minimum requirements.

Is there some sort of way to have near-equivalency between fonts between platforms? That's really the issue here - the Metal LAF is close enough to identical that it works, it's just the font throwing everything off. I've read a little bit about a way to specify small fonts in a .plist file that will make Mac fonts smaller, but that's the only shot in the dark I have right now, other than randomly trying fonts. If there's any way to choose some sort of cross-platform-friendly font, that would be great.

The alternative of developing a separate version for Mac/Linux and Windows isn't very appealing - I chose Java in part because it was supposed to be good cross-platform. And while it's still a bit better since Linux and Mac appear to be the same in appearance, it's not proving as cross-platform friendly as I'd hoped.

The invisibility problem is just that the larger font pushes every element of the pane I am using farther right, which pushes the ones on the right end off the panel, using Group Layout. The best alternative I've found is Absolute Layout, which at least ensures nothing will fall off the screen (at the expense of a bit of overlap). Needless to say, it isn't ideal given the font size issue, either.
santhosh varala kumar
Greenhorn

Joined: Nov 05, 2009
Posts: 25
It varies with system. basically it is system look and feel.

Basically we should UImanager tosetup as to use either systemlook& feel or cross platform look and fool.

If we want same font on all over platforms, the we need to explicitly use to set the font for the components. so the component should same font irrespective of the platform.
Thomas Kiersted
Greenhorn

Joined: Feb 24, 2007
Posts: 22

santhosh varala kumar wrote:It varies with system. basically it is system look and feel.

Basically we should UImanager tosetup as to use either systemlook& feel or cross platform look and fool.

If we want same font on all over platforms, the we need to explicitly use to set the font for the components. so the component should same font irrespective of the platform.


Thanks! I ended up adding a dialog asking the user (me right now) which font to use prior to having my regular GUI initialize, so that all components would use the font the user selected. That proved to be the key thing I needed, as that made testing considerably easier. It turns out most of the fonts render nearly identical on XP and Mac, and with a list of common fonts on both OS'es, I was able to test a number of them and come up with a couple (Tahoma and Trebuchet MS) that looked good on both platforms, so I can now default to those and ask the user only if neither font is present. I've yet to find an excellent default one for Linux, but it shouldn't be too difficult now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Default font is bigger on Mac/Linux than Windows