| | |
Adding and deleting a column in JTable
![]() |
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
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
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
•
•
Join Date: Mar 2004
Posts: 763
Reputation:
Solved Threads: 38
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.
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.
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
Wow i asked this question 2 years ago
Richard West
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
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
![]() |
Similar Threads
- deleting rows from a JTable (Java)
- adding columns (Java)
- adding and searching newly added column...HELP PLEASE!!!!! :( (ASP)
- auto resize only 1 column in jtable (Java)
- Adding a checkbox column dynamically (C#)
Other Threads in the Java Forum
- Previous Thread: NoClassDefFoundError
- Next Thread: Collating
| Thread Tools | Search this Thread |
6 @param actuate android api applet application arc array arrays automation balls binary bluetooth bold business byte c++ chat class client code codesnippet collections compare component coordinates database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans newbie nextline parameter php pong problem program programming project recursion recursive scanner sell server set sms sort sql string sun swing swt terminal threads tree web websites windows





