Swing less functionality than AWT?

R

Randyl

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
 
R

Roedy Green

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.
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top