Skip to main content

AWT Checkbox text gap

4 replies [Last post]
quecas
Offline
Joined: 2008-08-19

Hi,

I am in the process of guaranteeing that a legacy application based on applets will work across multiple platforms (windows ans suse for now).

The application developed and always tested on window, IE6 and MSJVM.

I have ported the application to SUN's VM 1.6 and most of it works fine except for the rendering of checkboxes, radiobuttons and their associated label. On windows they look fine, however, on SUSE (using firefox) the gap between the text and actual checkbox is huge, causing the text to crop in certain cases.

I am aware that a possible solution would be to setLabel(null) on the components and add a separate label next to it, but considering the size of the application, I was hoping that would be a last resort - besides why is it soooo different from one platform to another - there must be another solution to this, isn't there??

I have googled on this issue to no avail.

Any suggestions would be appreciated.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
quecas
Offline
Joined: 2008-08-19

Consider yourself lucky that you've never seen this one :-)

Anyway, thanks a lot for your input Anthony.

quecas
Offline
Joined: 2008-08-19

Hi Anthony,

Thanks for the quick reply.

Yip, I noticed earlier this morning (doing a search on setLayout) that the application was developed on the setLayout(null) paradigm.
Considering the size of the project and that time is always an issue with customers, is there any "best advice" to this issue.

anthony_p
Offline
Joined: 2006-07-24

I can't consider its size since I've never seen it :)

Anyways, from theoretical perspective it makes sense to use some real layout manager.

As to the fastest solution possible, I would just leave more room for the checkbox'es on the right. Thus they wouldn't overlap with other component no matter what gap there's between the box and its label.

anthony_p
Offline
Joined: 2006-07-24

Hello,

The behavioral difference you're referring to seems perfectly fine. Obviously, the implementation of the *native* windowing toolkit (I mean the AWT) differs quite a lot on different platforms. On Windows it uses the system, WinAPI checkbox. However, there's no "default" GUI toolkit on X systems, and therefore on X the checkbox is implemented from scratch. Of course, it may have different gaps, or use different fonts, or even look some way different than the one on MS Windows. And this is OK.

The real issue here is that your application is not aware of possible differences in sizes of the same component on different platforms - it just assumes that a component has constant size. But it isn't constant.

To help deal with such kind of problems LayoutManager's exist. They take into account the current size of components (and other properties, such as their minimum size, preferred size, and maximum size), and layout the components accordingly.

--
best regards,
Anthony