Naga Malleshwararao

Greenhorn
+ Follow
since Oct 22, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Naga Malleshwararao

Try to subclass DefaultTableModel.Use the following Code

import java.util.Vector;

import javax.swing.table.DefaultTableModel;

// Customizing the DefaultTableModel
class ResourceTableModel extends DefaultTableModel
{
public boolean isCellEditable(int row,int column)
{
return true;
}

public Class getColumnClass(int column)
{
Vector v = (Vector)dataVector.elementAt(0);
return v.elementAt(column).getClass();
}
}

In class where you are using JTable write this code

JTable resourceAllocation;
ResourceTableModel resourceModel = new ResourceTableModel();
resourceAllocation = new JTable(resourceModel);

String[] columns = new String[]{"Resource Name","Start Date","End Date","Allocation"};

for(int i = 0; i < columns.length; i++ )
{
resourceModel.addColumn(columns[i]);
}
18 years ago
Try this code


In order to insert textfield in to cell of JTable first you have to implement TableCellRenderer interface.

import java.awt.Component;

import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableCellRenderer;

class MISTextFieldRenderer extends JTextField implements TableCellRenderer {

public MISTextFieldRenderer(int size)
{
super(size);
try
{
setEditable(true);
}
catch(Exception exp)
{System.out.println(exp);}
}

public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column)
{
setText((String)value);
return this;
}
}

and then you have to set the table cell renderer as

JTable resourceAllocation;

TableColumn resourceColumn = resourceAllocation.getColumnModel().getColumn(0);

// Setting Cell Editor and Cell Renderer as ComboBox
MISComboBoxRenderer resourceName = new MISComboBoxRenderer();
resourceColumn.setCellRenderer(resourceName);
resourceColumn.setCellEditor(new DefaultCellEditor(resourceName));
18 years ago
First you should be clear where 10 is actually stored. If 10 is in database you can fetch the value from the database and you can compare it with the updated value in textfield. If you 10 is generated at run time you have to store the 10 in a variable before updating.
18 years ago
Hai try this method definition for getColumnClass.
public Class getColumnClass(int column)
{
Vector v = (Vector)dataVector.elementAt(0);
return v.elementAt(column).getClass();
}
18 years ago