This must be obvious, but I have searched for ages and can find no mention of it anywhere.
I'm creating an SWT TableViewer, and I want to have borders around my cells. How do I do this? No matter what I try, my cells are always borderless and it's difficult to tell where one cell ends and another begins. My code:
TableViewer outputViewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
outputViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TableViewerColumn col = new TableViewerColumn(outputViewer, SWT.LEFT | SWT.BORDER);
col.getColumn().setWidth(200);
col.getColumn().setText("Output");
col.getColumn().setResizable(true);
col.setLabelProvider(new ColumnLabelProvider());
outputViewer.getTable().setLinesVisable(true);
Related
I've a strange problem ...
by creating a (Jface) tree viewer with few column I always got created one more (emtpy) ....
/// TreeViewer creation:
treeViewer = new TreeViewer(parent, SWT.BORDER | SWT.FULL_SELECTION);
/// TreeViewerColumn creation!
for (int column = 0; column < columnsToAdd; column++) {
final TreeViewerColumn treeColumnText = new TreeViewerColumn(treeViewer, SWT.LEFT | SWT.BORDER);
treeColumnText.getColumn().setWidth(columnWidth);
treeColumnText.getColumn().setMoveable(false);
treeColumnText.getColumn().setText(model.getColumnName(column));
treeColumnText.setLabelProvider(columnLProvider[column]);
treeColumnText.getColumn().pack();
}
any idea why?
************* UPDATE
the parent of the treeViewer is the personsTabFolder:
personsTabFolder = new CTabFolder(persons, SWT.NONE);
just to highlight, I don't call any .layout(); on personsTabFolder!
_ _
Kasper
I solved it!
was using a CTabItem instead of a TabItem.
i have GridTableViewer, in that table showing rows are much.so i planned to reduce table height. But i am unable reduce the tableviewer size of the height.Can u anyone help me in this?
///pasting sample code
#Override
protected void addComponents(FormToolkit toolkit) {
myTableViewr=
new ExtendedGridTableViewer(client, getPage(), SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
Grid grid = myTableViewr.getGrid();
toolkit.adapt(grid, false, false);
grid.setHeaderVisible(true);
grid.setCellSelectionEnabled(false);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
grid.setLayoutData(gridData);
List<ColumnType<?>> columns = new ArrayList<ColumnType<?>>();
columns.add(new nameColumnType());
columns.add(new valueColumnType());
myTableViewr.createColumnGrid(toolkit, columns);
//myModel - my model code
LogoInsertionContentProvider contentProvide = new LogoInsertionContentProvider(this, myTableViewr, myModel);
myTableViewr.setContentProvider(contentProvide);
myTableViewr.setInput(myModel);
}
here, two columns and 3 rows only. but i am getting more than 10 rows
Your GridData for the table is:
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
which is asking to grab all available space. If you want to use a fixed height for the table use something like:
GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
gridData.heightHint = 500; // The height you want
I am learning to work with SWT.
I added two Tables to one Composite using:
TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
tabFolder.setLayoutData(BorderLayout.CENTER);
TabItem tbtmData = new TabItem(tabFolder, SWT.NONE);
tbtmData.setText("data");
scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
tbtmData.setControl(scrolledComposite);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
tableComposite = new Composite(scrolledComposite, SWT.NONE);
RowLayout rl_tableComposite = new RowLayout(SWT.HORIZONTAL);
tableComposite.setLayout(rl_tableComposite);
table_2 = new Table(tableComposite, SWT.BORDER | SWT.FULL_SELECTION);
table_2.setHeaderVisible(true);
table_2.setLinesVisible(true);
table_3 = new Table(tableComposite, SWT.BORDER | SWT.FULL_SELECTION);
table_3.setLayoutData(new RowData(261, 45));
table_3.setTopIndex(1);
table_3.setHeaderVisible(true);
table_3.setLinesVisible(true);
scrolledComposite.setContent(tableComposite);
scrolledComposite.setMinSize(tableComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
TabItem tbtmGraph = new TabItem(tabFolder, SWT.NONE);
tbtmGraph.setText("graph");
Canvas canvas = new Canvas(tabFolder, SWT.NONE);
tbtmGraph.setControl(canvas);
Now, in the window I see table_2 in the left and table_3 in the right. How to change the order in a runtime? Adding table_3 first is not an option in my case.
One more question. if i call table.setSize(0, 0); I don't see any changes in table appearance. I tried to call table.redraw() after that, but still, size of the table is not changing. where is my mistake?
You can call:
tableThree.moveAbove(tableTwo);
See the javadoc for more detail.
As for your second question:
Why do you want to set the size to 0? Doesn't Control#setVisible(false) do the trick?
I'm trying to edit values of individual columns of a Tree containing TreeColumns:
private Composite composite;
private Composite treeCompositeNdal;
private Tree treeNdalEditor;
private TreeColumn treeNameColumn ;
private TreeColumn treeValueColumn ;
[...]
treeCompositeNdal = new Composite(composite, SWT.BOTTOM);
treeCompositeNdal.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
treeCompositeNdal.setLayout(createNoMarginLayout(1, true));
treeCompositeNdal.setVisible(false);
treeNdalEditor = new Tree (treeCompositeNdal, SWT.BOTTOM|SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
treeNdalEditor.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
treeNdalEditor.setRedraw(true);
treeNdalEditor.setVisible(true);
treeNameColumn = new TreeColumn(treeNdalEditor, 0);
treeValueColumn = new TreeColumn(treeNdalEditor, 0);
treeNameColumn.setText("Name"); treeNameColumn.pack();
treeValueColumn.setText("Value"); treeValueColumn.pack();
I have added the selection listener available here.
As I understand, this will only account for the editing of the first column, which is the behavior I'm experiencing. I cannot modify the value column. Does anybody have any experience with this, or any documentation which I might use?
Thank you.
If JFace is an option for you, you should consider a TreeViewer with EditingSupport for your columns.
Ram's Blog shows you how to do that.
Additionally you should be aware of the following:
Users setting up an editable tree with more than 1 column have to pass the SWT.FULL_SELECTION style bit.
(see Eclipse Help)
Every second line is coloured on the table in the view.
I have the same table twice on the editor, but it doesn't show this separation:
My code of the lower table in the editor:
table1 = new Table(c, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION
| SWT.V_SCROLL);
TableLayout layout1 = new TableLayout();
table1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
layout1.addColumnData(new ColumnWeightData(20, 50, true));
layout1.addColumnData(new ColumnWeightData(20, 50, true));
layout1.addColumnData(new ColumnWeightData(20, 50, true));
layout1.addColumnData(new ColumnWeightData(20, 50, true));
table1.setLayout(layout1);
table1.setLinesVisible(true);
table1.setHeaderVisible(true);
TableColumn colReihe = new TableColumn(table1, SWT.LEFT);
colReihe.setText("Reihe");
TableColumn colPlatz = new TableColumn(table1, SWT.LEFT);
colPlatz.setText("Platz");
TableColumn colPreis = new TableColumn(table1, SWT.LEFT);
colPreis.setText("Preis");
TableColumn colStatus = new TableColumn(table1, SWT.LEFT);
colStatus.setText("verkauft");
this.tableViewer2 = new TableViewer(table1);
this.tableViewer2.setContentProvider(new ArrayContentProvider());
this.tableViewer2.setLabelProvider(new ITableLabelProvider() {
....some more code here....
this.toolkit.adapt(table1, true, true);
I don't really understand your question. Do you expect the table on the lower right of your screenshot to look like the table on the left? If that's the question, check, whether you call toolkit.adapt(table, true, true); with the left table as well, or try to remove that call with the right table. The FormToolkit sets a lot of colors and styles on widgets.