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 / June 2006

Tip: Looking for answers? Try searching our database.

Different combo boxes are cell editors

Thread view: 
hinz.adam@gmail.com - 02 Jun 2006 22:54 GMT
I would like to use combo boxes in my tables but have different values
in combo boxes that are in the same column. If found the following
example on the java website:

TableColumn sportColumn = table.getColumnModel().getColumn(2);
...
JComboBox comboBox = new JComboBox();
comboBox.addItem("Snowboarding");
comboBox.addItem("Rowing");
comboBox.addItem("Chasing toddlers");
comboBox.addItem("Speed reading");
comboBox.addItem("Teaching high school");
comboBox.addItem("None");
sportColumn.setCellEditor(new DefaultCellEditor(comboBox));

But this example only allows the same combo box for every row. How can
I fix this?

Thanks,
Adam
Rhino - 02 Jun 2006 23:08 GMT
>I would like to use combo boxes in my tables but have different values
> in combo boxes that are in the same column. If found the following
[quoted text clipped - 13 lines]
> But this example only allows the same combo box for every row. How can
> I fix this?

"Fix" suggests "broken" and I don't think this is broken; the concept
behind columns in a JTable are that each of values in the column are of the
same type and subject to the same renderers and editors. I'd be surprised if
you could set a different editor on different cells of the same column; that
would appear to defy the basic reasoning behind the JTable.

But I could be wrong. The best article I've ever seen on renderers and
editors is at
http://www-128.ibm.com/developerworks/library/j-jtable/. Maybe if you read
that you will get an idea on how to do what you want to do - or a
categorical statement that it can't be done at all. I haven't been through
the article in a fair while so I don't remember all the details of what the
author says.

--
Rhino
Christian Kaufhold - 04 Jun 2006 12:01 GMT
> I would like to use combo boxes in my tables but have different values
> in combo boxes that are in the same column. If found the following
> example on the java website:

> But this example only allows the same combo box for every row. How can
> I fix this?

Use a custom cell editor, which has different editorComponents for different
rows.


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



©2008 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.