urgent help on editing cell of a JTable
I have a JTable and i want to add JCombobox to only one cell in the JTable not for all cell in the column, and I want to be able to write in the rest of cells and to be enable to make some cells not enable for writing.
and this is my code.. please i want your replay as soon as possible :
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Label;
import javax.swing.JFrame;
import javax.swing.*;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
/*
* Created on Sep 17, 2005
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author a
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Proper extends JFrame implements TableCellRenderer {
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
Proper() {
setSize(300, 150);
topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel);
String columnNames[] = { "","" };
String dataValues[][] = { { "dd", "gg" }, {
"ff", "dgd" }, {
"", "" }};
table = new JTable(dataValues, columnNames);
scrollPane = new JScrollPane(table);
topPanel.add(scrollPane, BorderLayout.CENTER);
//TableColumn prmatiere = table.getColumnModel().getColumn(1);
TableColumn prmatiere = table.getColumnModel().getColumn(1);
JComboBox comboBox = new JComboBox();
comboBox.addItem("Snowboarding");
comboBox.addItem("Rowing");
prmatiere.setCellEditor(new DefaultCellEditor(comboBox));
TableColumn prmatiere1 = table.getColumnModel().getColumn(1);
getTableCellRendererComponent( table, comboBox, true,true,1,1);
JComboBox comboBox1 = new JComboBox();
comboBox1.addItem("Chasing toddlers");
comboBox1.addItem("Speed reading");
comboBox1.addItem("Teaching high school");
comboBox1.addItem("None");
//prmatiere1.setCellEditor(new DefaultCellEditor(comboBox1));
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
JComboBox box = new JComboBox( new String[] {"Location", "No", "Gender"} );
box.setBackground(Color.white);
return box;
}
public static void main(String args[]) {
final Proper t = new Proper();
t.setVisible(true);
//table = new JTable(rowData, columnNames);
}
}
/*public void getCellRenderer(int row, int column) {
if(row == 0)
return t;
return super.getCellRenderer(row, column);
}*/

