JTable & JComboBox
Hi, I have a problem with JTable when I want to insert a JComboBox.
My table has got five (of ten) column with JComboBox. The problem appears when i'm programming the aplication ( case 1 ) or when i want to insert values in the JComboBox ( case 2 )
Two cases ( two forms to program this code):
case (1) : In my class Control's Events, i have programmed:
void setUpColumnOrganizacion(JTable table,TableColumn organizacionColumn,ArrayList organizacion){
JComboBox comboBox = new JComboBox();
Iterator it = organizacion.iterator();
String nombre = null ;
while (it.hasNext()){
nombre = (String)it.next();
if (!duplicate(nombre,comboBox)){
comboBox.addItem(nombre);
}
}
organizacionColumn.setCellEditor(new DefaultCellEditor(comboBox));
//Set up tool tips for the sport cells.
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Haz clic para elegir organizacion");
organizacionColumn.setCellRenderer(renderer);
}
But the problem is that exist the "row 0 ( for example ) column 8"( JComboBox ) when you select an item, the program queries the Data Base and in the column 9 "( another JComboBox) insert others values. And how to i have programmed the another column with seemed code, the aplication insert into column the same values and i want only in the row 0 column 9.
Another form > Case (2), i am seeing examples of this page and i have found the next
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
public class TableRenderDemo extends JFrame
{
ArrayList editors = new ArrayList(3);
public TableRenderDemo()
{
// Create the editors to be used for each row
LINE 1>>>>>>>> String[] items1 = { "Red", "Blue", "Green" };
JComboBox comboBox1 = new JComboBox( items1 );
DefaultCellEditor dce1 = new DefaultCellEditor( comboBox1 );
editors.add( dce1 );
LINE 2>>>>>>>> String[] items2 = { "Circle", "Square", "Triangle" };
JComboBox comboBox2 = new JComboBox( items2 );
DefaultCellEditor dce2 = new DefaultCellEditor( comboBox2 );
editors.add( dce2 );
LINE 3>>>>>>>>String[] items3 = { "Apple", "Orange", "Banana" };
JComboBox comboBox3 = new JComboBox( items3 );
DefaultCellEditor dce3 = new DefaultCellEditor( comboBox3 );
editors.add( dce3 );
// Create the table with default data
Object[][] data =
{
{"Color", "Red"},
{"Shape", "Square"},
{"Fruit", "Banana"},
{"Plain", "Text"}
};
String[] columnNames = {"Type","Value"};
DefaultTableModel model = new DefaultTableModel(data, columnNames);
JTable table = new JTable(model)
{
// Determine editor to be used by row
public TableCellEditor getCellEditor(int row, int column)
{
if (column == 1 && row < 3)
{
return (TableCellEditor)editors.get(row);
}
else
return super.getCellEditor(row, column);
}
};
JScrollPane scrollPane = new JScrollPane( table );
getContentPane().add( scrollPane );
}
public static void main(String[] args)
{
TableRenderDemo frame = new TableRenderDemo();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
}
}
The problem in the two case is that the values of LINES 1, LINE 2 and LINE 3 are predefined, and how to say before, the program queries the Data Base.
What is the best form ? have I been mistaken in something ?
Sorry for my English!
Thanks.

