当前位置: 技术问答>java相关
菜鸟问题---JTable怎么用?
来源: 互联网 发布时间:2015-09-21
本文导语: 菜鸟问题---JTable怎么用? 怎么设置宽度,和显示的行数 怎么添加内容 | JTable is a user-interface component that presents data in a two-dimensional table format. The JTable has many facilities that make it possible to ...
菜鸟问题---JTable怎么用?
怎么设置宽度,和显示的行数
怎么添加内容
怎么设置宽度,和显示的行数
怎么添加内容
|
JTable is a user-interface component that presents data in a two-dimensional table format. The JTable has many facilities that make it possible to customize its rendering and editing but provides defaults for these features so that simple tables can be set up easily. For example, to set up a table with 10 rows and 10 columns of numbers:
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() { return 10; }
public int getRowCount() { return 10;}
public Object getValueAt(int row, int col)
{ return new Integer(row*col); }
};
JTable table = new JTable(dataModel);
JScrollPane scrollpane = new JScrollPane(table);
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() { return 10; }
public int getRowCount() { return 10;}
public Object getValueAt(int row, int col)
{ return new Integer(row*col); }
};
JTable table = new JTable(dataModel);
JScrollPane scrollpane = new JScrollPane(table);