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 }
  • 相关阅读:
    PHP笔试题
    找工作的几种方式
    ThinkPHP3.2.3学习笔记5---模板(一)
    PHP7新特性
    了解Web Uploader
    什么是云购网
    使用PDO操作数据库的好处
    MySQL与MongoDB的区别
    显示和编辑注解
    自定义验证逻辑
  • 原文地址:https://www.cnblogs.com/freeabyss/p/3187055.html
Copyright © 2011-2022 走看看