Dynamically showing and hiding columns in a SWT Table [message #458552] |
Fri, 15 July 2005 18:15 |
Eclipse User |
|
|
|
Originally posted by: aparasur.ugs.com
Hi,
Is it possible to dynamically show and hide columns in an SWT Table? I
couldn't find any methods that would let me control the visiblility of a
column. I am trying to avoid creating multiple tables.
Thanks in advance.
-Arvind
|
|
|
|
Re: Dynamically showing and hiding columns in a SWT Table [message #458555 is a reply to message #458554] |
Fri, 15 July 2005 18:26 |
Eclipse User |
|
|
|
Originally posted by: aparasur.ugs.com
I tried that. It didn't work.
-Arvind
"Andy Arhelger" <juggle@us.ibm.com> wrote in message
news:db8uje$tr7$1@news.eclipse.org...
> Try setting the column width to 0.
>
>
> Arvind Parasuram wrote:
>> Hi,
>> Is it possible to dynamically show and hide columns in an SWT Table? I
>> couldn't find any methods that would let me control the visiblility of a
>> column. I am trying to avoid creating multiple tables.
>>
>> Thanks in advance.
>> -Arvind
|
|
|
Re: Dynamically showing and hiding columns in a SWT Table [message #458579 is a reply to message #458555] |
Fri, 15 July 2005 20:41 |
Eclipse User |
|
|
|
Originally posted by: pijnmar.home.nl
Strange it doesn't work for you. This worked for me:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
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;
public class tabelcols {
private Table table;
protected Shell shell;
public static void main(String[] args) {
try {
tabelcols window = new tabelcols();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
protected void createContents() {
shell = new Shell();
shell.setLayout(new RowLayout());
shell.setSize(575, 378);
shell.setText("SWT Application");
table = new Table(shell, SWT.BORDER);
final RowData rowData = new RowData();
rowData.height = 311;
table.setLayoutData(rowData);
table.setLinesVisible(true);
table.setHeaderVisible(true);
final TableColumn tabCol1 = new TableColumn(table, SWT.NONE);
tabCol1.setWidth(100);
tabCol1.setText("New column");
final TableColumn tabCol2 = new TableColumn(table, SWT.NONE);
tabCol2.setWidth(100);
tabCol2.setText("New column");
final TableColumn tabCol3 = new TableColumn(table, SWT.NONE);
tabCol3.setWidth(100);
tabCol3.setText("New column");
final TableColumn tabCol4 = new TableColumn(table, SWT.NONE);
tabCol4.setWidth(100);
tabCol4.setText("New column");
final Button hideButton = new Button(shell, SWT.NONE);
hideButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
tabCol3.setWidth(0);
tabCol4.setWidth(0);
}
});
hideButton.setText("Hide");
final Button showButton = new Button(shell, SWT.NONE);
showButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
tabCol3.setWidth(100);
tabCol4.setWidth(100);
}
});
showButton.setText("Show");
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03708 seconds