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?
Related
I want to manage the position of component in GUI by easily drag and drop them at design page of Eclipse. This is the GUI I see in design page.(Right click>Test/Preview)
I think after I finish rearrange the component in design page, it will look similar when I RUN the app. But, this GUI appear.
The different appearance make me very hard to adjust the component, for example the width of DAY 2, the height of Medication, DOB : and the green background.
Please let me know if there is any solution to this problem. Thanks.
You can use the GridLayout where each day is a column and the subjects(diagnosis, treatment and so on) are the rows. And you create a composite in each grid cell (like Day1 & diagnosis) which contains your buttons for this day and the subject.
[EDIT]
My suggested implementation is: (SWT.BORDER marks all cells of the toplevel grid)
GridLayout topLevelLayout = new GridLayout();
topLevelLayout.numColumns = 4;
parent.setLayout(topLevelLayout);
// head row
Label label = new Label(parent, SWT.BORDER);
label.setText("Activity");
label = new Label(parent, SWT.BORDER);
label.setText("Day 1");
label = new Label(parent, SWT.BORDER);
label.setText("Day 2");
label = new Label(parent, SWT.BORDER);
label.setText("Day 3");
// new row - first cell
label = new Label(parent, SWT.BORDER);
label.setText("Diagnosis");
// Day1 & Diagnosis
GridLayout cellLayout = new GridLayout();
cellLayout.numColumns = 2;
Composite composite = new Composite(parent, SWT.BORDER);
composite.setLayout(cellLayout);
Button button = new Button(composite, SWT.NONE);
button.setText("ECG");
button = new Button(composite, SWT.NONE);
button.setText("Blood Pressure");
button = new Button(composite, SWT.NONE);
button.setText("Vital signs");
// other subjects of diagnosis at day 1...
// Day2 & Diagnosis
composite = new Composite(parent, SWT.BORDER);
// same layout like for day1 & diagnosis
composite.setLayout(cellLayout);
button = new Button(composite, SWT.NONE);
button.setText("ECG");
button = new Button(composite, SWT.NONE);
button.setText("Labs");
button = new Button(composite, SWT.NONE);
button.setText("Blood pressure");
// other subjects of diagnosis at day 2...
// Day3 & Diagnosis
composite = new Composite(parent, SWT.BORDER);
// same layout like for day1 & diagnosis
composite.setLayout(cellLayout);
button = new Button(composite, SWT.NONE);
button.setText("Stress Tests");
button = new Button(composite, SWT.NONE);
button.setText("Labs");
button = new Button(composite, SWT.NONE);
button.setText("Cardiac rhythm");
// other subjects of diagnosis at day 1...
label = new Label(parent, SWT.BORDER);
label.setText("Treatment");
Things like this happen with any designer. Usually they are an indicator of a location change occuring at runtime as the result of a dynamic parameter of some kind. Make sure that you having the correct padding on each of the buttons, and whatever you are using to contain the buttons in should be using a consistent spacing for each one. Also make sure that alignment within the containers is correct, and that both your buttons and the containers they are in are properly anchored.
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
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.
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.
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);