标题:abstractTableModel必须要用滚动条么?
只看楼主
msl12
Rank: 1
等 级:新手上路
帖 子:152
专家分:0
注 册:2015-2-6
结帖率:25%
 问题点数:0 回复次数:0 
abstractTableModel必须要用滚动条么?
代码如下:
---------------------------------------------------------------------
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

class Table extends AbstractTableModel {
    public String[] titles = { "姓名", "年龄" };
    public Object[][] userInfo = { { "李", 10 }, { "", 3 } };

    public int getColumnCount() {
        return this.titles.length;
    }

    public int getRowCount() {
        return this.userInfo.length;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        return this.userInfo[rowIndex][columnIndex];
    }

    public String getColumnName(int column) {
        return this.titles[column];
    }
}

public class Test20 {
    public static JFrame frame = new JFrame("Welcome");
    public static JTable table = null;

    public static void main(String[] args) {
        table = new JTable(new Table());
        //JScrollPane scr = new JScrollPane(table);
        //frame.add(scr, BorderLayout.CENTER);
        frame.add(table, BorderLayout.CENTER);        //为什么直接加入table显示不出列名,而改成上面被注释的代码,用滚动条才能显示列名?
        frame.setSize(300, 100);
        frame.setLocation(370, 160);
        frame.setVisible(true);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(1);
            }
        });
    }
}
搜索更多相关主题的帖子: public import 姓名 
2015-11-15 09:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-459219-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.714666 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved