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.
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.
I have a label. Sometimes, the text in it has overflow and doesn't show in the label. So, I would like to change the height of the label and also would like to when it has overflow it shows in its below line. How can I do that?
composite = (Composite) super.createDialogArea(parent);
composite.setLayout(new GridLayout());
GridData data = new GridData(GridData.FILL_HORIZONTAL);
Group grpModelProperties = new Group(composite, SWT.SHADOW_IN);
grpModelProperties.setLayout(new GridLayout(2, false));
grpModelProperties.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
Label l2 = new Label(grpModelProperties, SWT.NULL);
new Label(grpModelProperties, SWT.NONE);
l2.setLayoutData(data);
l2.setText("Text: " + Text);
//l2.setBounds(0, 0, 470, 200);
//l2.setSize( 470, 400 );
You can pass the style SWT.WRAP to the label constructor to specify that the text should automatically wrap in a new line if there is not enough horizontal space:
Label l2 = new Label(grpModelProperties, SWT.WRAP);
There are a couple of changes to make for this to work. First, you'll need to use the SWT.WRAP style bit in the Label constructor. In your case:
Label l2 = new Label(grpModelProperties, SWT.WRAP);
(As a side note, if you don't want a style set, you should use SWT.NONE, not SWT.NULL).
Also, you'll need to set a widthHint on the layout data for the top level element, otherwise your dialog will expand to accommodate the full width of the text. In your code:
composite.setLayout(new GridLayout());
GridData compositeGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
compositeGridData.widthHint = 200;
composite.setLayoutData(compositeGridData);
Slightly cleaned up, but your code should ultimately look something like this:
#Override
protected Control createDialogArea(Composite parent) {
composite = (Composite) super.createDialogArea(parent);
composite.setLayout(new GridLayout());
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.widthHint = 200;
composite.setLayoutData(data);
Group groupModelProperties = new Group(composite, SWT.SHADOW_IN);
groupModelProperties.setLayout(new GridLayout(2, false));
groupModelProperties.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
Label label = new Label(groupModelProperties, SWT.WRAP);
label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
label.setText("Text: The quick brown fox jumps over the lazy dog. This is a really long line of text that should wrap into a new line.");
return composite;
}
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?
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.