Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: jtable



Emil Edeholt wrote:

I'm trying to learn how to use JTables. And I don't quite get it. Is it
possible to somehow render a JRadioButton in one of the cols? Right now
the JRadioButton:s string value is displayed. Maybe someone could point
me in the right direction?

The advice to work through the tutorial is good. However, to answer your specific question, you need to replace the cell renderer. Since JTable (and JList and JTree) all take sets of Objects, some piece of code must render that Object on the screen. Since the only method of Object that makes any sense to present to the user is toString, that is what the default cell renderer does.

However, as others have posted, it makes no sense to me to place a
JRadioButton in a table cell. Normally JRadioButtons are part of a
ButtonGroup, and perform a select-one-of-many role. They do not stand
on their own. Placing a panel with a set of radio buttons makes sense,
as would a JComboBox or a JList (as suggested by a previous poster). If
you were planning on spreading the JRadioButtons of a ButtonGroup across
a table, row or column, I'd suggest you rethink your GUI design. If you
just want to layout a button group on a regular grid, try a JPanel with
GridLayout instead, a JTable is overkill. If what you want a bi-state
control, take a look at JCheckBox and JToggleButton. The JRadioButton
element implies to users the select-one-of-many semantics, if you aren't
using it in that role, it will confuse users. It might also fail to work
as expected -- e.g. how does one turn off a stand-alone JRadioButton?

If this is just a learning exercise, with no practical application, go
ahead and do what you like. One often learns "interesting" things when
ignoring sage advice :-).
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.