Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to make sorting jtable?  RSS feed

 
teguh sugiono
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen it but I don't understand
please help me
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok Thanks,
I will try it again
 
teguh sugiono
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!