I have written this stuff but it won't provide me the resizable feature of table.
Composite resultTableComposite = getToolkit().createComposite( parent );
GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 1 );
gridData.heightHint = 300;
gridData.widthHint = 250;
resultTableComposite.setLayoutData( gridData );
TableColumnLayout tableLayout = new TableColumnLayout();
resultTableComposite.setLayout( tableLayout );
resultTable = new TableViewer( resultTableComposite,
SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION );
getToolkit().adapt( resultTable.getTable() );
resultTable.getTable().setLinesVisible( true );
resultTable.getTable().setHeaderVisible( true );
The following image shows only 3 rows after filling 3 rows scroll added, but if we want to see 4 elements without scrolling we cant see. we want we can able to expand on resize the table:
Related
I'm currently developing an eclipse plugin and in that plugin, there is a form view as a design template. In that form view, I have added a Table and there should have two columns in width ratio of 1:2. And also I want that table to be responsive and dynamically change its column width in order to the formView page width.
The following code segment is the one I'm currently using.
Table table = new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.BORDER);
fd = new FormData();
fd.height = 200;
fd.top = new FormAttachment(removeTestCaseButton, 5);
fd.left = new FormAttachment(1);
fd.right = new FormAttachment(99);
table.setLayoutData(fd);
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn column1 = new TableColumn(testCaseTable, SWT.CENTER);
column.setText("column One");
TableColumn column2 = new TableColumn(testCaseTable, SWT.CENTER);
column2.setText("column Two");
form.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle area = form.getBody().getClientArea();
int width = area.width;
column1.setWidth(width / 3);
column1.setWidth(width * 2 / 3);
}
});
But here the problem is when I open the FormView it works fine. But my table is inside a Section. Once I expand or collapse the Section the table width is getting increased with appearing the horizontal scrollbar.
I just want a solid solution for this.
This is much easier to do using the JFace TableViewer with the TableColumnLayout and ColumnWeightData, but you will have to rework your code to use JFace style content and label providers for the table.
TableColumnLayout tableLayout = new TableColumnLayout();
// A separate composite containing just the table viewer is required
Composite tableComp = new Composite(parent, SWT.NONE);
tableComp.setLayout(tableLayout);
TableViewer viewer = new TableViewer(tableComp, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
TableViewerColumn col1 = new TableViewerColumn(viewer, SWT.LEAD);
col1.getColumn().setText("Column 1");
col1.setLabelProvider(.... label provider for column 1 ....);
// Weight for column
tableLayout.setColumnData(col1.getColumn(), new ColumnWeightData(60));
TableViewerColumn col2 = new TableViewerColumn(viewer, SWT.LEAD);
col2.getColumn().setText("Column 2");
col2.setLabelProvider(....... label provider for column 2 .....);
// Weight for column
tableLayout.setColumnData(col2.getColumn(), new ColumnWeightData(40));
viewer.getTable().setHeaderVisible(true);
viewer.getTable().setLinesVisible(true);
viewer.setContentProvider(ArrayContentProvider.getInstance());
viewer.setInput(.... input data for the viewer ....);
these are just sample codes. I created a GridLayout composite and removed the margins. But there are still spaces in between the rows.
Composite composite = new Composite(shell, SWT.NONE);
GridLayout gl_composite = new GridLayout(1, false);
gl_composite.marginWidth = 0;
gl_composite.marginHeight = 0;
composite.setLayout(gl_composite);
Composite composite_1 = new Composite(composite, SWT.BORDER);
GridData gd_composite_1 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_composite_1.heightHint = 52;
gd_composite_1.widthHint = 802;
composite_1.setLayoutData(gd_composite_1);
composite_1.setLayout(new GridLayout(1, false));
Composite composite_2 = new Composite(composite, SWT.BORDER);
GridData gd_composite_2 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_composite_2.widthHint = 803;
composite_2.setLayoutData(gd_composite_2);
I need the rows to not have any spaces in between. The composites are bordered since I need to have a line below . I'm new to SWT so..
Thanks!!
The verticalSpacing field of GridLayout sets the spacing between rows, so:
gl_composite.verticalSpacing = 0;
Use horizontalSpacing for spacing between columns.
The default for both values is 5
I have some trouble with Composite. I have written the following code:
final Composite mavniOptionsComposite = new Composite(parent, SWT.NONE);
mavniOptionsComposite.setLayout(new GridLayout(3, false));
final GridData textGridData = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
final Label mavniFormatingLabel = new Label(mavniOptionsComposite, SWT.None);
mavniFormatingLabel.setText(PFT.MAVNI_HISTORY.getExplanationLabelText());
mavniFormatingLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
final GridData mavniFormatingGridData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
final Button mavniHistoryRunCheckbox = new Button(mavniOptionsComposite, SWT.CHECK);
mavniHistoryRunCheckbox.setLayoutData(mavniFormatingGridData);
mavniHistoryRunCheckbox.setText(PFT.MAVNI_HISTORY.getExplanationLabelText());
mavniHistoryRunCheckbox.addSelectionListener(new mavniHistoryCheckBoxSelectionAdapter());
widgetsMap.put(PFT.MAVNI_HISTORY, mavniHistoryRunCheckbox);
final Button mavniRealtimeCheckbox = new Button(mavniOptionsComposite, SWT.CHECK);
mavniRealtimeCheckbox.setLayoutData(mavniFormatingGridData);
mavniRealtimeCheckbox.setText(PFT.MAVNI_REALTIME.getExplanationLabelText());
mavniRealtimeCheckbox.setEnabled(MyPreferences.isWmcDefined());
widgetsMap.put(PFT.MAVNI_REALTIME, mavniRealtimeCheckbox);
final Label toolNameLabel = new Label(mavniOptionsComposite, SWT.NONE);
toolNameLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
toolNameLabel.setText(PFT.TOOL_NAME.getExplanationLabelText());
final Text toolNameText = new Text(mavniOptionsComposite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
toolNameText.setLayoutData(textGridData);
widgetsMap.put(PFT.TOOL_NAME, toolNameText);
final Label toolVersionLabel = new Label(mavniOptionsComposite, SWT.NONE);
toolVersionLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
toolVersionLabel.setText(PFT.TOOL_VERSION.getExplanationLabelText());
final Text toolVersionText = new Text(mavniOptionsComposite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
toolVersionText.setLayoutData(textGridData);
widgetsMap.put(PFT.TOOL_VERSION, toolVersionText);
mavniOptionsComposite.setLayout(new GridLayout(2, false));
new MavniOptionViewer(MyPreferences.getMavniOptionsList()).createViewer(mavniOptionsComposite);
createExpandItem(parent, mavniOptionsComposite, "Mavni Options", com.mavni.ui.Activator
.getDefault().getImageRegistry().get(IImageKeys.EXECUTE.getPath()), false);
But I get the following behavior:
I would like the table to expand to on the full layout. As I understand that happens because I set setLayout(new GridLayout(3, false)); and the table contains only two columns. If I set mavniOptionsComposite.setLayout(new GridLayout(2, false)); then the table works as expected but the other elements are showing no in there place (like it should be now).
The wanted behviour:
At first I though to create two GridLayouts and insert them into one composite. I tried to search for a way to combine two layouts in one composite but could not find a way. I need one composite because createExpandItem works with only one composite. How to solve it?
EDIT: In the MavniOptionViewer I have:
public void createViewer(final Composite parent) {
commandsTable = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION);
commandsTable.setHeaderVisible(true);
commandsTable.setLinesVisible(true);
final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 5);
data.heightHint = 120;
commandsTable.setLayoutData(data);
final Map<ButtonTypeEnum, Button> buttons = ButtonComboFactory.createAddRemoveCombo(parent);
final Button add = buttons.get(ButtonTypeEnum.ADD);
final Button remove = buttons.get(ButtonTypeEnum.REMOVE);
...
I though of another possible solution. Is it possbile to change createViewer so the table will have 3 columns and the add remove buttons will be on seprated line. How to do it?
A Composite can only have one layout, you can't change it halfway. It will just end up using the last layout you set for everything.
You could use multiple Composites in a containing Composite.
You could keep your main Composite with a GridLayout of 3 columns and tell the table to occupy all 3 of these columns instead of 2 like you are doing now.
You can do that by changing the horizontal span of the table GridData from 2 to 3:
final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 5);
Also, you should not reuse GridData objects; from the documentation:
Every control in a Composite that is managed by a GridLayout must have
a unique GridData object.
Could anybody help me?
I have a table in SWT and simply I want to show some table items but the table only shows one item and the others with vertical scroll. I want to show everything, without scrolling. I tried with the option SWT_NO_SCROLL but is not working. I have a method that creates the table and other that populates it creating a new table item, they´re working good, the problem is that only shows the first item and the other are scrolling.
My code is:
private void createTable(Composite parent){
table = new Table (parent, SWT.BORDER);
TableColumn tcFile = new TableColumn(table, SWT.LEFT);
TableColumn tcStatus = new TableColumn(table, SWT.LEFT);
tcFile.setText("File");
tcStatus.setText("Status");
tcFile.setWidth(500);
tcStatus.setWidth(500);
table.setVisible(true);
table.setHeaderVisible(true);
}
private void populateTable(String file, String status){
TableItem item = new TableItem(table, SWT.LEFT);
item.setText(new String[] { file, status});
}
Composite top = new Composite(parent, SWT.WRAP);
GridLayout layout = new GridLayout();
layout.marginHeight = -5;
layout.marginWidth = 0;
top.setLayout(layout);
Composite banner = new Composite(top, SWT.WRAP);
banner.setLayoutData(new GridData(GridData.FILL, GridData.VERTICAL_ALIGN_BEGINNING, false, false));
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 10;
layout.numColumns = 5;
banner.setLayout(layout);
createTable(top);
You haven't specified any layout data for the Table, try something like:
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
table.setLayoutData(data);
If you don't have anything else that is setting the dialog/window size you may need to specify a table height hint:
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = 200; // Vertical size for table
table.setLayoutData(data);
I am having a problem getting SWT Text controls to lay out the way I want them to within a group. Specifically, I'm having a difficult time getting the verticalSpan passed to the GridData to be reflected in the GUI asset. In the example below, the 3 controls that I am unable to get to display correctly are descriptionText, defaultActionText, and defaultReportActionText, but translationText display displays correctly. I'm not sure what I'm doing incorrectly here so I appreciate any feedback!
Group:
paramsFieldComposite = new Group( upperRightComposite, SWT.BORDER );
// TODO: Change group to composite and remove .setText()
paramsFieldComposite.setText( "paramsFieldComposite" );
paramsFieldComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true, 1, 1 ) );
paramsFieldComposite.setLayout( new GridLayout( 2, true ) );
Translation Controls (working as I would expect with a width of 1 and height of 3):
Label hostnameLabel = new Label( paramsFieldComposite, SWT.NONE );
hostnameLabel.setLayoutData( new GridData( SWT.FILL, SWT.FILL, false, false, 1, 1 ) );
hostnameLabel.setText( configResourceBundle.geti18nDisplay( "HostnameLabel" ) );
Label translationLabel = new Label( paramsFieldComposite, SWT.NONE );
translationLabel.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, false, 1, 1 ) );
translationLabel.setText( configResourceBundle.geti18nDisplay( "TranslationLabel" ) );
hostnameText = new TextControl( paramsFieldComposite, SWT.BORDER );
hostnameText.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, false, 1, 1 ) );
hostnameText.setEditable( true );
translationText = new TextControl( paramsFieldComposite, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP );
translationText.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, false, 1, 3 ) );
translationText.setEditable( true );
Description/Action Controls (not working as I'm expecting, I want them to all have a height of 3 instead of 1):
Label descriptionLabel = new Label( paramsFieldComposite, SWT.NONE );
descriptionLabel.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, false, 2, 1 ) );
descriptionLabel.setText( configResourceBundle.geti18nDisplay( "DescriptionLabel" ) );
descriptionText = new TextControl( paramsFieldComposite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI );
descriptionText.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true, 2, 3 ) );
descriptionText.setEditable( true );
Label defaultActionLabel = new Label( paramsFieldComposite, SWT.NONE );
defaultActionLabel.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, false, 1, 1 ) );
defaultActionLabel.setText( configResourceBundle.geti18nDisplay( "DefaultActionLabel" ) );
Label defaultReportActionLabel = new Label( paramsFieldComposite, SWT.NONE );
defaultReportActionLabel.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, false, 1, 1 ) );
defaultReportActionLabel.setText( configResourceBundle.geti18nDisplay( "DefaultReportActionLabel" ) );
defaultActionText = new TextControl( paramsFieldComposite, SWT.BORDER | SWT.V_SCROLL );
defaultActionText.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, false, 1, 3 ) );
defaultActionText.setEditable( true );
defaultReportActionText = new TextControl( paramsFieldComposite, SWT.BORDER | SWT.V_SCROLL );
defaultReportActionText.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, false, 1, 3 ) );
defaultReportActionText.setEditable( true );
Here is what the GUI looks like.
The difference between the behaviour of translationText and defaultActionText is quite easy to explain.
You told both to span 3 rows. However, while the height of these three rows of translationText is defined by other Widgets (hostnameText, instanceLabel, instanceText), this is not the case for defaultActionText. There are no other widgets in these three rows (except for defaultReportActionText). So the height will be set to the necessary height.
You can manually increase this height by setting the heightHint of the GridData:
GridData data = new GridData( SWT.FILL, SWT.FILL, true, false, 1, 3 );
data.heightHint = 80;
defaultActionText.setLayoutData(data);
defaultReportActionText.setLayoutData(data);
The result can be seen here:
To get a more exact result for the height, you could use:
data.heightHint = hostnameText.computeSize(SWT.DEFAULT, SWT.DEFAULT).y
+ instanceLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y
+ instanceText.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;