• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anybody know how to remove a row from a JTABLE?
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

To remove a row from a Jtable use the flg. method
yourJTable.removeRow(rownum);
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot for the help.
 
Tom Pelly
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic