简体   繁体   中英

Sort rows in JFace Treeviewer

I'd like to sort the rows of my TreeViewer alphabetically, because every time I start the simulation, the rows of the tree are ordered randomly.

I found some methods to sort only by column with setSortColumn(TreeColumn column) . Is there an easy way to sort the tree by rows?

Call the setComparator method of the viewer to provide a class based on ViewerComparator to sort the entries in your view.

If you just want to sort by the values of the labels returned by your label provider you can just use the base ViewComparator class:

viewer.setComparator(new ViewerComparator());

If your want your sorting to be more complex use a class extending ViewerComparator and override the sort method (perhaps also category ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM