943,946 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 13796
  • Java RSS
Oct 5th, 2004
0

Adding and deleting a column in JTable

Expand Post »
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 freesoft_2000@yahoo.com

Thank You

Yours Sincerely

Richard West
Similar Threads
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Jul 5th, 2006
0

Re: Adding and deleting a column in JTable

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
arvind_upadhya is offline Offline
1 posts
since Jul 2006
Jul 7th, 2006
0

Re: Adding and deleting a column in JTable

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.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
Jul 12th, 2006
0

Re: Adding and deleting a column in JTable

Hi everyone,

Wow i asked this question 2 years ago

Richard West
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: NoClassDefFoundError
Next Thread in Java Forum Timeline: Collating





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC