zoukankan      html  css  js  c++  java
  • Java简单的表格模型

     1 import java.util.Vector;
     2 import javax.swing.*;
     3 import javax.swing.table.*;
     4 public class abyssModel  extends JScrollPane{
     5 
     6 
     7         /**
     8          * 
     9          */
    10         private static final long serialVersionUID = 1L;
    11         private DefaultTableModel tableModel;// 定义表格模型对象
    12         private JTable table;// 定义表格对象
    13 
    14         public abyssModel(Vector<String> columnNames, Vector<Vector<String>> tableValues) {
    15             // 创建指定表格列名和表格数据的表格模型
    16             tableModel = new DefaultTableModel(tableValues, columnNames);
    17             table = new JTable(tableModel);// 创建指定表格模型的表格
    18             table.setRowSorter(new TableRowSorter<>(tableModel));// 设置表格的排序器
    19             // 设置表格的选择模式为单选
    20             table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    21             //关闭自动调整功能,从而使用水平滚动条
    22             table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    23             setViewportView(table);
    24     }
    25     //添加一行数据
    26     public void addRow(Vector rowValues){
    27         tableModel.addRow(rowValues);
    28     }
    29     //删除指定行的数据
    30     public void removeRow(int selectedRow){
    31         tableModel.removeRow(selectedRow);
    32     }
    33     //获得被选中行
    34     public int getSelectedRow(){
    35         return table.getSelectedRow();
    36     }
    37 }
  • 相关阅读:
    【AGC010E】Rearranging(博弈,图论,拓扑排序)
    【ARC074F】Lotus Leaves(最小割)
    【ARC069F】Flags(2-SAT,Tarjan,线段树优化建图)
    [CTS 2019] 氪金手游
    HDU
    LOJ
    LOJ
    [TJOI 2015] 概率论
    [AGC 018F] Two Trees
    LOJ
  • 原文地址:https://www.cnblogs.com/freeabyss/p/3187055.html
Copyright © 2011-2022 走看看