+ 1
How to create a dropdown menu in which sort by 1-votes 2-likes 3-dislikes 4-replies are present in java?
Sorting by taking into account various fields
1 Antwort
0
I think that you have an array with your data (or list)
I would store the data as beans (classes jzst for storing)
class Data {
private int likes, votes, dislikes, votes, replies;
//getters and setters and other stuff
}
then you have to sort the array (list) by the selected thing: best way to do that is using lamdas:
Arrays.sort (myArr,(a,b)->Integer.compare (a.getVotes (),b.getVotes ());
Dropdown menus are created using jmenu and jmenu item.javase/tutorial/uiswing/components/menu.html
Now you need to create an onclicklistener that sorts the stuff every time a menuitem is clicked.