Java表格模型事件示例 (一)
2014-11-24 08:41:41 】 浏览:10706
Tags:Java 表格 模型 事件 示例

package com.han;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Arrays;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;

* 表格模型事件示例


  • A component generally gains the focus when the user clicks it,
    * or when the user tabs between components, or otherwise interacts
    * with a component. A component can also be given the focus programmatically,
    * such as when its containing frame or dialog-box is made visible.
    * The snippet of the codes below shows how to give a particular component
    * the focus every time the window gains the focus.
    * @author HAN
    public class TableModelEvent_1 extends JFrame {

    private static final long serialVersionUID = -8581492063632813033L;

    public TableModelEvent_1() {
    // TODO Auto-generated constructor stub
    final Container container = getContentPane();
    Vector tableColumnNames = new Vector();
    Vector> tableva lues = new Vector>();
    for (int i = 1; i < 5; i++) {
    Vector vector = new Vector();
    vector.add("A" + i);
    vector.add("B" + i);
    tableva lues.add(vector);
    final DefaultTableModel defaultTableModel = new DefaultTableModel(
    tableva lues, tableColumnNames);
    final JTable table = new JTable(defaultTableModel);
    JScrollPane scrollPane = new JScrollPane();
    container.add(scrollPane, BorderLayout.CENTER);
    JPanel panel = new JPanel();
    container.add(panel, BorderLayout.SOUTH);
    JLabel labelA = new JLabel("A: ");
    final JTextField textFieldA = new JTextField(15);
    JLabel labelB = new JLabel("B: ");
    final JTextField textFieldB = new JTextField(15);
    JButton buttonAdd = new JButton("添加");
    JButton buttonDel = new JButton("删除");
    JButton buttonDeselected = new JButton("取消选择");
    buttonAdd.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    Java表格模型事件示例 (一)

  • 首页 上一页 1 2 3 4 下一页 尾页 1/4/4
    】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
    上一篇Java自动计算表格某一数字列的和(.. 下一篇Java捕获窗口状态事件