Java JTable set column selection
import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableModel; public class Main extends JPanel { public static void main(String[] args) { JFrame f = new JFrame("JTable"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new Main()); f.pack();/* w w w .j a v a 2 s .c om*/ f.setVisible(true); } public Main() { TableModel dataModel = new MyTableModel(); JTable table = new JTable(dataModel); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setColumnSelectionAllowed(true); table.setRowSelectionAllowed(false); // Select an additional range of columns - columns 1 to 2 table.addColumnSelectionInterval(1, 2); JScrollPane jsp = new JScrollPane(table); this.add(jsp); } } class MyTableModel extends AbstractTableModel { @Override public int getRowCount() { return 30; } @Override public int getColumnCount() { return 3; } @Override public Object getValueAt(int row, int col) { return Math.pow(row, col + 1); } @Override public Class<?> getColumnClass(int col) { return getValueAt(0, col).getClass(); } }