Tree (SWT) mit Tabelle (TreeTable)




package com.sowas.swtdemo;
 
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
 
public class ColumnTree{
 
   public static void main(String[] args) {
      Display display = new Display();
      final Shell shell = new Shell(display);
      shell.setLayout(new FillLayout());
 
      Tree tree = new Tree(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
      tree.setHeaderVisible(true);
      tree.setLinesVisible(true);
      TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
      column1.setAlignment(SWT.LEFT);
      column1.setText("Land/Stadt");
      column1.setWidth(160);
      TreeColumn column2 = new TreeColumn(tree, SWT.RIGHT);
      column2.setAlignment(SWT.LEFT);
      column2.setText("Straße");
      column2.setWidth(100);
      TreeColumn column3 = new TreeColumn(tree, SWT.RIGHT);
      column3.setAlignment(SWT.LEFT);
      column3.setText("Nr.");
      column3.setWidth(20);
 
      TreeItem item00 = new TreeItem(tree, SWT.NONE);
      item00.setText(new String[] { "Deutschland", "", ""});
      TreeItem item01  = new TreeItem(item00, SWT.NONE);
      item01.setText(new String[] { "Bremen", "", ""});
      TreeItem item02  = new TreeItem(item00, SWT.NONE);
      item02.setText(new String[] { "Hamburg", "", ""});
      TreeItem item10 = new TreeItem(item00, SWT.NONE);
      item10.setText(new String[] { "Baden-Württemberg", "", ""});
      TreeItem item11  = new TreeItem(item10, SWT.NONE);
      item11.setText(new String[] { "Heidelberg", "Hauptstraße", "4"});
      TreeItem item20 = new TreeItem(item00, SWT.NONE);
      item20.setText(new String[] { "Niedersachsen", "", ""});
      TreeItem item21  = new TreeItem(item20, SWT.NONE);
      item21.setText(new String[] { "Hannover", "Herrenhäuserstraße", "44"});
      TreeItem item22  = new TreeItem(item20, SWT.NONE);
      item22.setText(new String[] { "Wolfsburg", "Am Finkenhaus", "16"});		
 
      shell.pack();
      shell.open();
      while (!shell.isDisposed()) {
         if (!display.readAndDispatch()) {
            display.sleep();
         }
      }
      display.dispose();
   }
}

Siehe auf JFace-Variante


Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007