• 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

how to make sorting jtable?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[HELP]
I have a table
how to make sorting jtable??

private void search(){

DefaultTableModel tabModel = (DefaultTableModel) Tabel_Barang.getModel();
tabModel.setRowCount(0);


try{
strSql = "";
strSql = " SELECT kodebarang,category,merk,itembarang,type,satuan FROM masterbarang ";
stmt=koneksi.createStatement();
rslt=stmt.executeQuery(strSql);

while(rslt.next()){
String kodebarang=rslt.getString("kodebarang");
String category=rslt.getString("category");
String merks=rslt.getString("merk");
String itembarang=rslt.getString("itembarang");
String type=rslt.getString("type");
String satuan=rslt.getString("satuan");

Object[] data = {kodebarang,category,merks,itembarang,type,satuan};
tabModel.addRow(data);
AutofitTableColumns.autoResizeTable(Tabel_Barang, true);
}


}catch (SQLException ex) {
Logger.getLogger(contoh.class.getName()).log(Level.SEVERE, null, ex);
}

}
sorting.JPG
[Thumbnail for sorting.JPG]
I suppose the sorting here
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.
In future, while posting code, please UseCodeTags. I have added them this time for you. As you can see they make the code much more easier to read and understand.

Check out the "Sorting and Filtering" section in http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
 
teguh sugiono
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've seen it but I don't understand
please help me
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which part did you not understand? The simplest is literally adding one line table.setAutoCreateRowSorter(true);
Show us your SSCCE code, tell us where you are stuck and we will help point you in the right direction
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

teguh sugiono wrote:I've seen it but I don't understand



It is difficult to see how anyone here could put it more simply than is done in the "Sorting and Filtering" section of the tutorial ! At the start of the section it indicates how as a starting point that you just invoke one method on your JTable ! What could we add ?
 
teguh sugiono
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok Thanks,
I will try it again
 
teguh sugiono
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm a newbie,
I hope there is help in the same instance
I really do not know and can not do it
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic