Java JTable add row selection

Description

Java JTable add row selection


import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class Main {
  public static void main(String[] args) {
    JFrame f = new JFrame("JTable example");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    /*from  w  w  w .j a  v  a 2  s . c o m*/
    String[] columnNames = { "Ordinal" };
    String[][] tableData = {{ "One" }, //
                            { "Two" },//
                            { "Three" } };
    
    JTable table = new JTable(tableData, columnNames);
    
    f.add(new JScrollPane(table));
    f.pack();
    
    f.setVisible(true);

    table.addRowSelectionInterval(1, 1);
  }
}



PreviousNext

Related