15.3 Table Data
We've seen the
TableColumnModel, which stores a lot of information about the structure of a table but doesn't contain the actual data. The data that's displayed in a
JTable is stored in a TableModel. The TableModel interface describes the minimum requirements for a model that supplies the information necessary to display and edit a table's cells and to show column headers. The
AbstractTableModel fills out most of the TableModel interface, but leaves the methods for retrieving the actual data undefined. The
DefaultTableModel extends AbstractTableModel and provides an implementation for storing data as a vector of vectors. We'll look at both the abstract and default table models in more detail later in this chapter.
15.3.1 The TableModel Interface
All of the table models start with this interface. A table model must be able to give out information on the number of rows and columns in the table and have
access to the values of the cells of the table. The TableModel interface also has methods that can be used to encode information about the columns of the table (such as a localized name or class type) separate from the column model.
|
15.3.1.1 Properties
The TableModel interface supports the properties shown in
Table 15-9.
The columnCount is the number of columns in the data model. This does not have to match the number of columns reported by the column model. Likewise,
rowCount is the number of rows in the data model. columnName and
columnClass are indexed properties that let you retrieve the name of the column and the class of objects in the column. The name used in the table model is distinct from anything used in the
TableColumn class. For both properties, remember that the index refers to the table model, regardless of where the column appears on the screen.
Table 15-9. TableModel properties
Property
Data type
get
is
set
Default value
columnCount
|
int
|
·
|
|
|
|
rowCount
|
int
|
·
|
|
|
|
15.3.1.2 Events
As you may have come to expect from other models in the Swing package, the
TableModel has its own event type, TableModelEvent, generated whenever the table changes. A full discussion of the
TableModelEvent class and the TableModelListener appears later in this chapter.
public void addTableModelListener(TableModelListener l)
public void removeTableModelListener(TableModelListener l)
Add or remove listeners interested in receiving table model events.
15.3.1.3 Cell methods
These methods let you obtain and change the values of individual cells:
public Object getValueAt(int rowIndex, int columnIndex)
Return the value of the cell at (rowIndex, columnIndex). Base types (int,
float, etc.) are wrapped in an appropriate Object.
public boolean isCellEditable(int rowIndex, int columnIndex)
Return true if the cell at (rowIndex, columnIndex) can be edited.
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
Set the value of the cell at (rowIndex, columnIndex) to
aValue. As with the getValueAt( ) method, you may need to wrap primitive data types in an
Object (like Integer) before using them to set the value of a cell.
分享到:
相关推荐
这个是Java.Swing.OReilly
From lambda expressions and JavaFX 8 to new support for network programming and mobile development, Java 8 brings a wealth of changes. This cookbook helps you get up to speed right away with hundreds ...
是一本英文版的书,很经典,示例代码很多,复制粘贴即可运行,只要看懂代码就可以,当然能看懂解释更好……
Oreilly Python for Data Analysis: Data Wrangling with Pandas, NumPy, and IPython Oct 20, 2017 最终版,完整版,清晰版,原版
OReilly Java Swing 英文版,pdf格式.
OReilly.Java.I.O.2nd.Edition.May.2006 Java的io包主要包括: 1. 两种流:字节流(byte Stream)和字符流(character stream),这两种流不存在所谓的谁代替谁、谁比谁高级之说,它们互为补充,只是侧重点不同...
Oreilly::Snippets.process( asciidoc_string ) 片段用法 查看O'Reilly的。 您的标记中的代码段看起来像这样。 [filename="coffeetech.js", language="js" identifier="IDENTIFIER"] snippet~~~~ Put any ...
JavaPerformceTuning-Oreilly.pdf
JavaSwing_O-Reilly英文版,好看的东西要分享
com.oreilly.servlet
Oreilly 上传组件源码Oreilly 上传组件源码Oreilly 上传组件源码
With Java RMI, you'll learn tips and tricks for making your RMI code excel. This book provides strategies for working with serialization, threading, the RMI registry, sockets and socket factories, ...
This is the source code referenced in the O'Reilly Online Course: Developing Android Applications with Java. More information can be found here: http://training.oreilly.com/androidapps-java/
在Scikit上学习机器学习-学习Tensorflow -oreilly-Geron:从O'reilly上学习使用Scikit-Learn和Tensorflow进行机器学习-Geron
The goal of this concise book is not just to teach you Java, but to help you think like a computer scientist. You’ll learn how to program—a useful skill by itself—but you’ll also discover how to ...
Think Data Structures Algorithms and Information Retrieval in Java-OReilly(2017)
该存储库包含有关O'Reilly 在线培训的说明和示例。 日期在培训时间表中列出。 它还包含Kubernetes 使用的。 先决条件 在本培训中,我们将使用运行本地Kubernetes实例。 我们将使用名为kubectl的客户端访问此本地...
Oreilly - Python Cookbook,python编程人员必备学习手册
( OReilly Ethics of Big Data (2012)大数据伦理学OReilly Ethics of Big Data