Tree not showing up when using TreeColumn - java

I'm having trouble displaying a Tree which contains column definitions:
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");
treeValueColumn.setText("Value");
The Tree displays fine if I comment out the treeNameColumn and treeValueColumn lines. What am I doing wrong?

Try calling TreeColumn#pack() on both columns after filling in your content. This will force the TreeColumns to resize according to their content.

Related

How to reduce table size in Table viewer in RCP?

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

How to reorder Tables

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?

Cannot edit value in Tree containing TreeColumns

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)

Why SWT List fills all composite?

Hi I have a problem with the layouts in SWT, I want to create an application with 4 equal sized lists. When the lists are empty, each looks good, but when I will fulfill one of the lists with data that covers the entire composite.
and lists with data:
I know that it by wrong layout, so I'll show you some source:
shlPirotechnikafcwnxrap.setLayout(new FillLayout(SWT.HORIZONTAL));
......
Composite mainComposite = new Composite(shlPirotechnikafcwnxrap,
SWT.NONE);
mainComposite.setLayout(new FormLayout());
......
Composite rightCenterComposite = new Composite(mainComposite, SWT.NONE);
rightCenterComposite.setLayoutData(new FormData());
rightCenterComposite.setLayout(new GridLayout());
rightCenterComposite.setLayoutData(GUIHelper.getFormData(5, 100, 30, 100));
TabFolder tabFolder = new TabFolder(rightCenterComposite, SWT.NONE);
tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
/**
* TAB ITEM
*/
TabItem tbtmSql = new TabItem(tabFolder, SWT.NONE);
tbtmSql.setText("SQL");
/**
* Composite inside TabItem
*/
Composite sqlTabComposite = new Composite(tabFolder, SWT.NONE);
GridLayout gl_sqlTabComposite = new GridLayout();
gl_sqlTabComposite.makeColumnsEqualWidth = true;
gl_sqlTabComposite.numColumns = 2;
sqlTabComposite.setLayout(gl_sqlTabComposite);
sqlTabComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
tbtmSql.setControl(sqlTabComposite);
Group grpSowaKluczoweSql = new Group(sqlTabComposite, SWT.NONE);
grpSowaKluczoweSql.setLayout(new FormLayout());
grpSowaKluczoweSql.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
grpSowaKluczoweSql.setText("S\u0142owa kluczowe i operatory SQL:");
List listSlowaKluczoweSql = new List(grpSowaKluczoweSql, SWT.BORDER | SWT.V_SCROLL);
listSlowaKluczoweSql.setLayoutData(new FormData());
listSlowaKluczoweSql.setLayoutData(GUIHelper.getFormData(0, 100, 0, 100));
Group grpTabele = new Group(sqlTabComposite, SWT.NONE);
grpTabele.setLayout(new FormLayout());
grpTabele.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
grpTabele.setText("Nazwy tabel:");
List listTabele = new List(grpTabele, SWT.BORDER | SWT.V_SCROLL);
listTabele.setLayoutData(new FormData());
listTabele.setLayoutData(GUIHelper.getFormData(0, 100, 0, 100));
It is because of this: sqlTabComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); You are using FILL + grab excess space. Try using appropriate layout constants, like BEGINNING for horizontal alignment and TOP for vertical. Also set grabExcessVerticalSpace to false. Check all related places.

SWT.Table behaves differently with same code (Eclipse RCP)

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.

Categories