[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: TableColumn pack problem
|
I'm using Eclipse Version: 3.0.0 on Windows XP. This snippet illustrates
another problem I'm having. The first time the table is shown, there is
extra space after the last column that looks like it's wide enough for a
scroll bar. Then as you press the button, the last column grows everytime.
Here's my snippet:
/*
* Created on Jan 24, 2005 by Robin Wilson
*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
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 TableColumnProblemExample {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Table Column Pack");
GridLayout vertical = new GridLayout();
vertical.numColumns = 1;
shell.setLayout(vertical);
final Table table = new Table(shell, SWT.SINGLE);
table.setHeaderVisible(true);
table.setLinesVisible(true);
final TableColumn col1 = new TableColumn(table,SWT.CENTER);
col1.setText("Column 1");
final TableColumn col2 = new TableColumn(table,SWT.CENTER);
col2.setText("Column 2");
col1.pack();
col2.pack();
Button button = new Button(shell, SWT.PUSH);
button.setText("Fill Data");
button.addSelectionListener( new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
//table.layout(true);
table.setRedraw(false);
table.removeAll();
String [] data1 = { "1", "2" };
String [] data2 = { "3", "4" };
TableItem item1 = new TableItem(table, SWT.NONE);
item1.setText( data1 );
TableItem item2 = new TableItem(table, SWT.NONE);
item2.setText( data2 );
col1.pack();
col2.pack();
shell.pack();
table.setRedraw(true);
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
Steve Northover wrote:
1) Which platform?
2) Post a stand alone snippet that shows the problem.
"Robin Wilson" <robinwilson@xxxxxxx> wrote in message
news:cstmik$116$1@xxxxxxxxxxxxxxxxxx
The first time I create my table and pack all the columns it looks great.
After, I change the contents and call pack on each column again the last
column expands. I'm sure I must be doing something wrong. Can someone
please
give me a hint or point me to a tutorial on tables? I've been searching
and
searching but with no luck so far.
Thanks!