This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable" Watch "JTable" New topic
Author

JTable

Tom Pelly
Greenhorn

Joined: Jun 29, 2001
Posts: 14
Does anybody know how to remove a row from a JTABLE?
Bala Hari
Greenhorn

Joined: Nov 14, 2001
Posts: 7

To remove a row from a Jtable use the flg. method
yourJTable.removeRow(rownum);
Jennifer Garrett
Greenhorn

Joined: Oct 31, 2001
Posts: 13
I think you need to use DefaultTableModel for adding and removing rows. Your code might be something like this:
String[] mycolumns = {"column 1 title", "column 2 title"};
String[][] mydata = {{"foo", "bar"}, {"aaa", "bbb"}};
DefaultTableModel mytableModel = new DefaultTableModel(mydata, mycolumns);
JTable mytable = new JTable(mytableModel);
JScrollPane myscrollpane = new JScrollPane(mytable);
// ... somehwere later, whenever you want to remove a row...
int rowNumber = 0;
mytableModel.removeRow(rowNumber); // remove the first row
Tom Pelly
Greenhorn

Joined: Jun 29, 2001
Posts: 14
Thanks alot for the help.
Tom Pelly
Greenhorn

Joined: Jun 29, 2001
Posts: 14
Need a bit more help on this JTable please...
Is there any way to set the widths of the colums? So if I wanted the first colum to start up twice the width of the second (without manually having to drag it), how would I do that?
Thanks.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You'll need to mess with the TableColumnModel.

First, get the TableColumnModel.


Then, get the width of the first column.


Then, set the width of the second column.


And you're done!

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable
 
Similar Threads
jtable
Jtable
JTable
JTable