Adding and deleting a column in JTable

Reply

Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 7
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Adding and deleting a column in JTable

 
0
  #1
Oct 5th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1
Reputation: arvind_upadhya is an unknown quantity at this point 
Solved Threads: 0
arvind_upadhya arvind_upadhya is offline Offline
Newbie Poster

Re: Adding and deleting a column in JTable

 
0
  #2
Jul 5th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: Adding and deleting a column in JTable

 
0
  #3
Jul 7th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 7
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: Adding and deleting a column in JTable

 
0
  #4
Jul 12th, 2006
Hi everyone,

Wow i asked this question 2 years ago

Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond

Tell me what type of software do you like and what would you pay for it

http://www.daniweb.com/techtalkforums/thread19660.html
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC