Hi everyone,
I seem to have in problem in adding columns and deleting colums in the JTable. When my program initializes there are five columns and six rows. I can append as many rows as i want and the column headers i have left to default which is (A, B, C and etc) but then problem happens when i start the deletion of the columns. The program deletes the columns one by one but their column headers seem to be stuck at the last value that the column was initialized at or in this case "D" . What i need is a way that when the colums are added the column header names are default. what i mean is that when i delete the up to column header "B" the program continues adding the columns but with its column header name continued from "B" (ie. "C", "D")

The below function is the function that deletes the columns one by one
and the other function adds the columns one by one.

public void deletecolumn (JTable table, int p)
{
TableColumn TableColumn1 = table.getColumnModel().getColumn(p);
w = TableColumn1.getModelIndex(); 
table.removeColumn(TableColumn1);   
}

public void insertcolumn (JTable table2)
{
//TableModel1 is the class instance off the  DefaultTableModel i declare
//above
TableModel1 = (DefaultTableModel)table2.getModel();
TableColumn col = new TableColumn(TableModel1.getColumnCount() - 1);
table2.addColumn(col);
}

Could someone please show me or tell me what i am doing wrong.

My e-mail is [snipped]

Thank You

Yours Sincerely

Richard West

Recommended Answers

All 3 Replies

Hi ,

How to make the added column editable. This added column in not there in TableModel and hence we cannot use isCellEditable() method. Is there any solution to make the added column editable?

hey arvind, how bout you make your own thread instead of asking questions in someone else's topic.


I think you should create your own table model. You could extend the DefaultTableModel to give you something to start with, or do your own from scratch with the interface. The main method you need to be concerned with is getColumnName().

I'm a little confused with how your column names are retrieved now. From the way I understand what you're saying, you have columns ABCDE and by removing B you know show ABCD instead of ACDE.

Hi everyone,

Wow i asked this question 2 years ago

Richard West

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.