JTable(Object[][] rowData,Object[] columnNames)
表格数据 列名集合
setSelectionMode(int selectionMode) 设置选择模式
3种选择模式:
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION 随便选
ListSelectionModel.SINGLE_INTERVAL_SELECTION 连选(相邻)
ListSelectionModel.SINGLE_SELECTION 单选
表格属性与操作:
table.setSelectionBackground(Color.YELLOW); 设置选中行的字体颜色
table.setSelectionForeground(Color.RED); 设置选中行的背景色
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setRowHeight(20);//设定行高20像素
table.getRowCount();//获取行数
表格索引位置都是从0开始:
table.getColumnName(0);//获取第一列的名称
table.getValueAt(0,0);//获取1行1列的值
import javax.swing.*;import java.awt.*;public cla