Extra space in the Table of Swt [message #194620] |
Fri, 16 February 2007 08:38  |
Eclipse User |
|
|
|
Hi All,
I am creating a table in the SWT. But i am getting a small extra column at
the end of my Table...
Is there any way to overcome this....
Regards,
Zakir
|
|
|
|
|
|
Re: Extra space in the Table of Swt [message #194714 is a reply to message #194649] |
Fri, 16 February 2007 14:15   |
Eclipse User |
|
|
|
Originally posted by: wayne.beaton._NOSPAM_eclipse.org
For kicks, I decided to do a quick implementation of a table that
automatically resizes it's columns to fill the available space. You can
easily adapt this to weight columns to make them consume some portion of
the available space.
I turned off the resize ability (i.e. the user can't resize) but you can
accommodate for this as well, if desired.
The example is based on SWT snippet #38
More snippets at: http://www.eclipse.org/swt/snippets/
/*********************************************************** ********************
* Copyright (c) 2000, 2004 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 example snippet: create a table (columns, headers, lines)
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
public class Snippet38 {
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
final Table table = new Table (shell, SWT.MULTI | SWT.BORDER |
SWT.FULL_SELECTION);
table.setLinesVisible (true);
table.setHeaderVisible (true);
String[] titles = {"Column1", "Column2", "Column3"};
for (int i=0; i<titles.length; i++) {
TableColumn column = new TableColumn (table, SWT.NONE);
column.setResizable(false);
column.setText (titles [i]);
}
int count = 128;
for (int i=0; i<count; i++) {
TableItem item = new TableItem (table, SWT.NONE);
item.setText (0, "x");
item.setText (1, "y");
item.setText (2, "z");
}
//table.setSize (table.computeSize (SWT.DEFAULT, 200));
//shell.pack ();
table.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
TableColumn[] columns = table.getColumns();
int columnWidth = table.getClientArea().width /
columns.length;
for(int index=0;index<columns.length;index++)
columns[index].setWidth(columnWidth);
}
});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
|
|
|
Re: Extra space in the Table of Swt [message #194744 is a reply to message #194714] |
Sat, 17 February 2007 00:11  |
Eclipse User |
|
|
|
Thanks Wayne,
My problem is resolved...
I was answering another question and by mistake i had writeen the comment
for that question to you... sorry for my previous message...
Thanks again for you suggestion...
Regards,
Zakir
|
|
|
Powered by
FUDForum. Page generated in 0.09274 seconds