jTable and Sorting

前端 未结 2 1943
清酒与你
清酒与你 2020-12-12 01:59

How do i sort jtable column using radio button?

my jtable is defaultTableModel not vectors.

I have already achieve when user press on column header, it will

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 02:35

    Add an actionlistener to the radiobutton, sort and set the tableModel. The Vector argument is an 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
      }
    });
    

提交回复
热议问题