www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.dwt - Snippet 272

reply Ty Tower <towerty msn.com.au> writes:
module snippet272;

/*******************************************************************************
 * Copyright (c) 2000, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
//package org.eclipse.swt.snippets;

/*
 * Table snippet: specify custom column widths when a column is packed
 *  
 * For a detailed explanation of this snippet see

 * 
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 * 
 *  since 3.2
 */
import dwt.DWT;
import dwt.widgets.Display;
import dwt.widgets.Shell;
import dwt.widgets.Table;
import dwt.widgets.TableColumn;
import dwt.widgets.TableItem;
import dwt.widgets.Event;
import dwt.widgets.Listener;

import tango.io.Stdout;
import tango.util.Convert; 


static void main(char[][] args) {
  Display display = new Display(); 
  Shell shell = new Shell(display);
  shell.setBounds(10,10,400,200);
  Table table = new Table(shell, DWT.NONE);
  table.setBounds(10,10,350,150);
  table.setHeaderVisible(true);
  table.setLinesVisible(true);
  final TableColumn column0 = new TableColumn(table, DWT.NONE);
  column0.setWidth(100);
  final TableColumn column1 = new TableColumn(table, DWT.NONE);
  column1.setWidth(100);
  column0.addListener(DWT.Selection, new class Listener {
    public void handleEvent(Event event) {
      column0.pack();
    }
  });
  column1.addListener(DWT.Selection, new class Listener {
    public void handleEvent(Event event) {
      column1.pack();
    }
  });
  for (int i = 0; i < 5; i++) {
    TableItem item = new TableItem(table, DWT.NONE);
    item.setText(0, "item " ~ to!(char[])(i) ~ " col 0");
    item.setText(1, "item " ~ to!(char[])(i) ~ " col 1");
  }

  /*
   * NOTE: MeasureItem is called repeatedly.  Therefore it is critical
   * for performance that this method be as efficient as possible.
   */
  table.addListener(DWT.MeasureItem, new class Listener {
    public void handleEvent(Event event) {
      event.width *= 2;
    }
  });

  shell.open();
  while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) display.sleep();
  }
  display.dispose();
}
Jun 07 2008
parent Tower Ty <tytower hotmail.com.au> writes:
Oh if you want to see what each line does

http://www.eclipse.org/articles/article.php?file=Article-CustomDrawingTableAndTreeItems/index.html
Jun 07 2008