How to create a dropdown menu in which sort by 1-votes 2-likes 3-dislikes 4-replies are present in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

23rd Mar 2017, 4:35 PM
Nikhil Kumar
Nikhil Kumar - avatar
1 Answer
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.
24th Mar 2017, 6:30 AM
No One
No One - avatar