• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JCombo box inside a JTable Cell?

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

Thanks
Ben
(Nathan Pruett - edited to remove page widening line in code block.)
[ March 10, 2004: Message edited by: Nathan Pruett ]
 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
Thanks
ben
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic