ListSelectionModel.SINGLE_SELECTION : ListSelectionModel « javax.swing « Java by API






ListSelectionModel.SINGLE_SELECTION

  
import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

public class MainClass {

  public static void main(final String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" },
        { "three", "3" } };
    final String headers[] = { "English", "Digit" };
    
    TableModel fixedColumnModel = new AbstractTableModel() {
      public int getColumnCount() {
        return 2;
      }
      public String getColumnName(int column) {
        return headers[column];
      }
      public int getRowCount() {
        return 3;
      }
      public Object getValueAt(int row, int column) {
        return rows[row][column];
      }
    };
    
    
    
    JFrame frame = new JFrame("Scrollless Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(fixedColumnModel);
    
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    
    frame.add(new JScrollPane(table), BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
  }
}

           
         
    
  








Related examples in the same category

1.ListSelectionModel.SINGLE_INTERVAL_SELECTION
2.ListSelectionModel: getMaxSelectionIndex()
3.ListSelectionModel: getMinSelectionIndex()
4.ListSelectionModel: isSelectedIndex(int index)
5.ListSelectionModel: isSelectionEmpty()
6.ListSelectionModel: setAnchorSelectionIndex(int index)
7.ListSelectionModel: setLeadSelectionIndex(int index)