Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Tutorials Swt Demonstrates TableTree

Related Tutorials


 
 

Share on Google+Share on Google+

Demonstrates TableTree

Advertisement
SWT provides the class TableTree to display the hierarchy of items in a tabular form. In the given example, we have defined three columns for the table tree. The method getTable() of class TableTree returns the underlying table control.

Demonstrates TableTree

     

This section shows you Table Tree.

SWT provides the class TableTree to display the hierarchy of items in a tabular form. In the given example, we have defined three columns for the table tree. The method getTable() of class TableTree  returns the underlying table control . The method table.setHeaderVisible(true) makes the header visible. The class TableColumn creates the columns in the TableTree. The class TableTreeItem adds the items to the TableTree.

 

 

Here is the code of TableTreeExample.java

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class TableTreeExample {
  static int COL = 3;

  private static void createContents(final Shell shell) {
  shell.setLayout(new FillLayout());

  TableTree tableTree = new TableTree(shell, SWT.NONE);
  Table table = tableTree.getTable();
  table.setHeaderVisible(true);
 
  for (int i = 0; i < COL; i++) {
  new TableColumn(table, SWT.LEFT).setText("Column " + (i + 1));
  }
  for (int i = 0; i < COL; i++) {
  TableTreeItem parent = new TableTreeItem(tableTree, SWT.NONE);
  parent.setText(0, "Book " + (i + 1));
  parent.setText(1, "Core Java");
  parent.setText(2, "Advanced Java");

  for (int j = 0; j < COL; j++) {
  TableTreeItem child = new TableTreeItem(parent, SWT.NONE);
  child.setText(0, "Java " + (j + 1));
  child.setText(1, "Core Java Topics");
  child.setText(2, "Advanced Java Topics");
  }
  parent.setExpanded(true);
  }
  TableColumn[] tableColumn = table.getColumns();
  for (int i = 0, n = tableColumn.length; i < n; i++) {
  tableColumn[i].pack();
  }
  }
  public static void main(String[] args) {
  TableTreeExample example=  new TableTreeExample();
 Display display = new Display();
  Shell shell = new Shell(display);
  shell.setText("TableTree");
  createContents(shell);
  shell.pack();
  shell.open();
  while (!shell.isDisposed()) {
  if (!display.readAndDispatch()) {
  display.sleep();
  }
  }
  display.dispose();
  }
}

Output will be displayed as:

Download Source Code

     

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 24, 2008

Related Tutorials

Discuss: Demonstrates TableTree  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com