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.
Related
I need to center the content of the cells of the fourth column of my table, now they start on left.
This is the table:
Table membersTable = new Table(clubComposite, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION);
membersTable.setLinesVisible(true);
membersTable.setHeaderVisible(true);
membersTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
TableColumn tblclmnName = new TableColumn(membersTable, SWT.NONE);
tblclmnName.setWidth(150);
tblclmnName.setText("Nombre");
TableColumn tblclmnCommonPhoneNumber = new TableColumn(membersTable, SWT.NONE);
tblclmnCommonPhoneNumber.setWidth(120);
tblclmnCommonPhoneNumber.setText("Teléfono");
TableColumn tblclmnCommonMoney = new TableColumn(membersTable, SWT.NONE);
tblclmnCommonMoney.setWidth(150);
tblclmnCommonMoney.setText("Participación Habitual");
TableColumn tblclmnPayed = new TableColumn(membersTable, SWT.CENTER);
tblclmnPayed.setWidth(50);
tblclmnPayed.setText("Pagado");
// populate Table
for (int i=0; i<50; i++) {
TableItem tableItem = new TableItem(membersTable, SWT.CENTER);
tableItem.setText(new String[] {"person "+i, "610610620", "100", ""});
tableItem.setImage(3, uncheckedImage);
}
I tried doing this:
TableColumn tblclmnPayed = new TableColumn(membersTable, SWT.CENTER);
But it seems that it only centers the title of the column, not it's content.
It is possible to achieve my needs on Java SWT?
In order to center the content of a column, you need to specify the SWT.CENTER style bit for the TableItem as well.
For example:
final Table table = new Table(shell, SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
table.setHeaderVisible(true);
table.setLinesVisible(true);
final TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setText("Column 1");
column1.setWidth(75);
final TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText("Column 2");
column2.setWidth(75);
final TableColumn column3 = new TableColumn(table, SWT.CENTER);
column3.setText("Column 3");
column3.setWidth(75);
for (int i = 0; i < 5; i++) {
new TableItem(table, SWT.CENTER).setText(new String[] { "a", "b", "c" });
}
Note that this will only affect the contents for the column which also specifies SWT.CENTER, not the content for the other columns.
Edit in regards to centering an image:
I don't believe it is possible to center an image within the table row via the style bits, since they seem to be ignored.
One alternative would be to use a paint listener to draw the image with the correct padding to center the image in the column (See: How to align image to center of table cell (SWT Table)). Note that with this method the row is not resized based on the size of the image, so unless your image is tiny/the same height as the row, you'll have to do some additional work to keep the image form being cut off.
The CheckboxTableViewer allows creation a single checklist.
But how do I put the header of such a column since the column itself is not created by a TableColumn.
tableViewer = CheckboxTableViewer.newCheckList(parent, SWT.SINGLE| SWT.BORDER | SWT.FULL_SELECTION);
tableViewer.add(checkListNames.get(0));
tableViewer.add(checkListNames.get(1));
tableViewer.add(checkListNames.get(2));
tableViewer.add(checkListNames.get(3));
tableViewer.add(checkListNames.get(4));
tableViewer.add(checkListNames.get(5));
final Table table = tableViewer.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
System.out.println(table.getColumnCount()); // this returns a zero
table.setHeaderVisible(true);
table.setLinesVisible(true);
You need to use TableLayout and TableViewerColumn to define a column so you can set the header text.
The minimum code would be:
TableLayout layout = new TableLayout();
TableViewerColumn col = new TableViewerColumn(tableViewer, SWT.LEAD);
col.getColumn().setText("Text");
layout.addColumnData(new ColumnWeightData(100));
table.setLayout(layout);
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)
i try to use an org.eclipse.jface.viewers.CheckboxTableViewer, as a component of a org.eclipse.jface.wizard.WizardPage. I created it this way:
public void createControl(Composite parent) {
composite = new Composite(parent, SWT.NULL);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
setControl(composite);
/* CheckboxTableViewer */
viewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
final Table table = viewer.getTable();
GridData data1 = new GridData();
data1.grabExcessHorizontalSpace = true;
data1.grabExcessVerticalSpace = true;
data1.horizontalSpan = 2;
data1.horizontalAlignment = SWT.FILL;
data1.verticalAlignment = SWT.FILL;
table.setLayoutData(data1);
table.setHeaderVisible(true);
table.setLinesVisible(true);
checkboxColumn = new TableColumn(table, SWT.LEFT);
...
the content of the viewer is inserted dynamically by a contentprovider. Everything works fine on gnome. While testing this on windows 7 (64 and 32 bit also), i am not able to select any entries of that view. Mouseclicks just seems to have no impact on the view.
I added a mouselistener to the table, and the mouseUp-/Down event is fired, selectionChanged and doubleClick on the viewer is not fired. Anyone who can explain this behaviour to me?
thx in advance,
hage
(i already posted this question in the eclipse forum without any response yet: http://www.eclipse.org/forums/index.php/t/250953/ )
You have to add another style flag while creating the CheckboxTableViewer: SWT.FULL_SELECTION
viewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION);
You can now select rows in the table by a single clicking.