In this section, you will study how to create a table.
SWT provides the classes Table, TableItem, TableColumn of package org.eclipse.swt.widgets to create a table. In the given example, we have create an ArrayList of Tennis players along with their countries and rankings.
The method composite.setLayout() sets the layout of table. The method table.setHeaderVisible(true) makes the header of the table visible. The method table.setLinesVisible(true) makes the line visible between the rows and columns. The class TableColumn creates the columns and the method column.setText() sets the header name. The method table.setRedraw(false) causes drawing operations to be ignored. If it is set to true, it performs drawing operations. The Iterator iterates the Array List. The TableItem class sets the items to the table. The method String.valueOf(player.getRanking()) converts the integer value to String.
Here is the code of SimpleTableExample.java
Output will be displayed as:
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial