Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JTable with Drop down issue.

 
Ranch Hand
Posts: 32
MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm facing a issue with Jtable. My Jtable has got a column with the price drop down. That drop down will have some list of prices. Whenever i'm selecting a value from one drop down, automatically the same value gets selected in the all the below rows of the same column.

How to fix this issue?? Please provide a solution for this issue.


Thanks and Regards,
Kiran Kumar K.V
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you got so far and where are you stuck?
 
Rancher
Posts: 3262
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the JTable API and follow the link to the section in the Swing tutorial on "How to Use Tables" for a working examples that use a combo box as an editor.
 
kopparapu v kiran kumar
Ranch Hand
Posts: 32
MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my render class

public class MyComboBoxRenderer extends JComboBox implements javax.swing.table.TableCellRenderer {
public MyComboBoxRenderer(String[] items) {
super(items);
}

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground());
} else {
setForeground(table.getForeground());
setBackground(table.getBackground());
}
//table.setValueAt(value, row, column);
setSelectedItem(value);
return this;
}
}

Editor class:

public class MyComboBoxEditor extends DefaultCellEditor {
public MyComboBoxEditor(String[] items) {
super(new JComboBox(items));
}
}

and I'm passing the values like this:
String[] values = {"a", "b"};

//...
TableColumn col = jTable1.getColumnModel().getColumn(4);
col.setCellEditor(new com.gmis.analysis.renderers.MyComboBoxEditor(values));
col.setCellRenderer(new MyComboBoxRenderer(values));


This is how my code is...

Please help me to solve this issue. It is very much important for me.
 
Rob Camick
Rancher
Posts: 3262
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Please help me to solve this issue.



I did give you the solution. The tutorial has a working example.

There is no need to create a custom renderer.

Also, use the "Code" tags when posting code.
 
kopparapu v kiran kumar
Ranch Hand
Posts: 32
MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Rob,


Thank you very much!! This tutorial helped me to solve this issue. Yes you are right for this case we dont need to have a custom renderer.

A big Thanks to you again!!

bye,
kiran
 
Where does a nanny get ground to air missles? Protect this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic