![]() | ![]() | ![]() | ![]() | ![]() |
The TableView displays data from different types of tabular data sources and enables users to interact with live data.
The Java class in this sample creates and displays a simple table view. For simplicity, this sample uses its own static data model for the TableView. In most real-world use cases, users will connect to live data and not create their own data model. For more information about how to connect the TableView to live data, see Sample 25994.
Here are the steps for creating a simple TableView:
The resulting code will look something like this:
...
Create arrays with row data and column names
...
DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
TableViewtableView1 = new TableView(model);
|
The code shown on the Full Code tab will create a DefaultTableModel and display a default TableView with that model.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Tip: For help with building a SAS Java Project, see SAS Note 32218.
package samples;
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import com.sas.swing.visuals.tableview.TableView;
public class TableViewExampleApp {
protected TableView table;
public static void main(String[] args) {
// set swing look and feel with system look and feel
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
TableViewExampleApp simpleApp = new TableViewExampleApp();
simpleApp.createFrame(args).setVisible(true);
}
// create a frame and add the table view to it
public JFrame createFrame(String[] args) {
JFrame frame = new JFrame(this.getClass().getName());
Container contentPane = frame.getContentPane();
contentPane.setLayout(new BorderLayout());
// for the simplicity of this sample, create some static data
// in real-world use cases, the user would most likely connect to live
// data
String data1[] = { "Bob", "42", "M", "Sailing" };
String data2[] = { "Mary", "33", "F", "Gardening" };
String data3[] = { "Jane", "27", "F", "Shopping" };
String data4[] = { "Tom", "65", "M", "Reading" };
String data5[] = { "Dave", "23", "M", "Skiing" };
String rowData[][] = { data1, data2, data3, data4, data5 };
String columnNames[] = { "Name", "Age", "Sex", "Hobby" };
// create a new table model with the static data
DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
// create a new TableView with the model just created
table = new TableView(model);
// create a scrollPane and put the table view in it
JScrollPane scrollPane = new JScrollPane(table);
// add the scrollPane to the content pane
contentPane.add(scrollPane, BorderLayout.CENTER);
contentPane.setSize(500, 250);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
return frame;
}
}
|
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
| Type: | Sample |
| Date Modified: | 2008-07-09 15:31:28 |
| Date Created: | 2005-12-19 15:23:21 |
| Product Family | Product | Host | Product Release | SAS Release | ||
| Starting | Ending | Starting | Ending | |||
| SAS System | SAS AppDev Studio | Microsoft Windows Server 2003 Enterprise Edition | 3.2 | 9.1 TS1M3 SP4 | ||
| Microsoft Windows Server 2003 Datacenter Edition | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows NT Workstation | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows 2000 Professional | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows 2000 Server | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows 2000 Datacenter Server | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows 2000 Advanced Server | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft® Windows® for x64 | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows Server 2003 Standard Edition | 3.2 | 9.1 TS1M3 SP4 | ||||
| Microsoft Windows XP Professional | 3.2 | 9.1 TS1M3 SP4 | ||||
| Windows Vista | 3.2 | 9.1 TS1M3 SP4 | ||||





