Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Swing less functionality than AWT?

Thread view: 
Randyl - 25 Jul 2007 03:48 GMT
Greetings:

Recently I finished developing a Java applet that reads a file and
produces a report from the data. This applet is localized and uses the
mechanism of the ResourceBundle files. I am happy with this.

Part of the controls on the applet display area are a series of
Checkbox radio buttons so that the user can select which language will
be used to display program-progress messages and what language will be
used for the report itself.

Each Checkbox radio button has a label (setLabel), retrieved from a
ResourceBundle, a name (setName), hardcoded, and a locale (setLocale),
also hardcoded. In this fashion I can use getName to retrieve the
proper ResourceBundle and getLocale to control various date and time
localized formatting issues, all independently from each other.

The Checkbox radio buttons are all grouped in one CheckboxGroup
object. Up to this point everything is fine. However, once I decided
to change the controls from AWT to Swing is when the proverbial
seven-shades-of-you-know-what hit the fan.

First, the Checkbox button had to become JRadioButtons and the
setLabel had to become setText; no problem. The setName and setLocale
remained as-is. So far so good.

This is where the wheels fall of this wagon. The previous AWT
CheckboxGroup was changed to a Swing ButtonGroup in order to
accommodate the new Swing JRadioButton buttons. During run-time the
currently-selected button for an AWT CheckboxGroup is retrieved via
getSelectedCheckbox which returns the actual Checkbox object and I can
set the ResourceBundle file and the locale appropriately, but a Swing
ButtonGroup retrieves the currently-selected button via getSelection
which returns this lousy ButtonModel object that has only one pitiful
String. For some reason or the other I expected to be able to access
the JRadioButton but never discovered how to do this or how to set and
retrieve any other property on this ButtonModel monstrosity.

Question:

Why in the world would a Swing ButtonGroup have LESS functionality
than an AWT CheckboxGroup?

Why would a JRadioButton be transmogrified into a ButtonModel and
there not be a corresponding method of ButtonModel Class to go get the
original object? What advantage is there in making the JRadioButton
object inaccessible?

Is this the way things are supposed to be or did I miss something in
the documentation?

Best Regards,
Randyl Kent Plampin
Roedy Green - 25 Jul 2007 08:13 GMT
>First, the Checkbox button had to become JRadioButtons and the
>setLabel had to become setText; no problem.

You are not quite that restricted. The Swing equivalent is called a
JCheckBox, a JRadioButton or a JToggleButton. Checkbox uses getState
and setState, where JCheckBox uses isSelected and setSelected.
JCheckBox uses a checkmark; JRadioButton uses a dot in a circle, and
JToggleButton uses ordinary-looking buttons.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 25 Jul 2007 08:15 GMT
>Why in the world would a Swing ButtonGroup have LESS functionality
>than an AWT CheckboxGroup?

I think they wanted to decouple the group management from the buttons
themselves so it would be easier to roll your own buttons or group
management.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.