JTable and Sorting

How to sort jtable column using switch?

my jtable by defaultTableModel not vectors.

I already reached, when the user clicks on the column heading, it will be sorted, now I have to implement using the switch.

What would be the best way to achieve this?

+2
source share
2 answers

To make the view programmatically, add the following code to your listener:

DefaultRowSorter sorter = ((DefaultRowSorter)table.getRowSorter()); ArrayList list = new ArrayList(); list.add( new RowSorter.SortKey(2, SortOrder.ASCENDING) ); sorter.setSortKeys(list); sorter.sort(); 
+4
source

Add an actionlistener to the radio block, sort and set the Model table. The Vector argument is the input to defaultTableModel.

 final JTable table = new JTable(); JRadioButton button = new JRadioButton(); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //sort your data here table.setModel(new DefaultTableModel(sortedDate)); table.repaint();// maybe revalidate too } }); 
+1
source

Source: https://habr.com/ru/post/1400610/


All Articles