wood burning stoves
The moose likes Swing / AWT / SWT and the fly likes JCombo box  inside a JTable Cell? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JCombo box  inside a JTable Cell?" Watch "JCombo box  inside a JTable Cell?" New topic

JCombo box inside a JTable Cell?

ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
Hello All,
Is there a way where I can get a JCombo Bok in each cell of my JTable ?
my JTable Currently looks like this:

(Nathan Pruett - edited to remove page widening line in code block.)
[ March 10, 2004: Message edited by: Nathan Pruett ]
ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
I just thought I would let you know that I have done it like so.
But with doing it like this I cannot choose between each item that I put in the ComboBox it is all ways set to "hello". How can I make it so that I can choose between each item?
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

There's an example of using a JComboBox as a TableCellEditor in the Swing Tutorial.

You are seeing "hello" every time because every time the TableCellRenderer you have created is called, you return a brand new combo box. You should use TableCellEditor instead, and you should extend JComboBox, or have a single JComboBox instance in your class that you return the same reference to each time. You would set the current value by using the "value" parameter being sent to the getTableCellEditor() method.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link: http://aspose.com/file-tools
subject: JCombo box inside a JTable Cell?
It's not a secret anymore!