I want to put 3 fixed size group in the composite in A side. And I want to place the image and the label middle of this group. My example image and code is below. The problem is the groups are resize according to label size in them and labels were written top of the group, but I want the place groups as equal fixed size to cover width of A side and labels should be vertically middle of the group.
private void designComposite() {
Section sectionA = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
sectionA.setText("A");
Composite sectionClientA = toolkit.createComposite(sectionA);
sectionClientA.setLayout(new RowLayout());
Composite dynamicDataComp = toolkit.createComposite(sectionClientA);
dynamicDataComp.setLayout(new RowLayout());
Group group_incom = new Group(dynamicDataComp, SWT.NONE);
group_incom.setLayout(new RowLayout());
Label lbl_img_incom = new Label(group_incom, SWT.CENTER);
Image img_incom = new Image(lbl_img_incom.getDisplay(),
"<path>");
lbl_img_incom.setImage(img_incom);
group_incom.setText("# of Incoming Messages :");
Label lbl_incomMsg = toolkit.createLabel(group_incom, "99", SWT.CENTER | SWT.VERTICAL);
Font incomFont = new Font(lbl_incomMsg.getDisplay(), new FontData("Arial", 12, SWT.BOLD));
lbl_incomMsg.setFont(incomFont);
lbl_incomMsg.pack();
Group group_outgo = new Group(dynamicDataComp, SWT.NONE);
group_outgo.setLayout(new RowLayout());
Label lbl_img_outgo = new Label(group_outgo, SWT.CENTER);
Image img_outgo = new Image(lbl_img_outgo.getDisplay(),
"<path>");
lbl_img_outgo.setImage(img_outgo);
group_outgo.setText("# of Outgoing Messages :");
Label lbl_outgoMsg = toolkit.createLabel(group_outgo, "145639612", SWT.CENTER);
Font outgoFont = new Font(lbl_outgoMsg.getDisplay(), new FontData("Arial", 13, SWT.BOLD));
lbl_outgoMsg.setFont(outgoFont);
lbl_outgoMsg.pack();
Group group_error = new Group(dynamicDataComp, SWT.NONE);
group_error.setLayout(new RowLayout());
Label lbl_img_error = new Label(group_error, SWT.CENTER);
Image img_error = new Image(lbl_img_error.getDisplay(),
"<path>");
lbl_img_error.setImage(img_error);
group_error.setText("# of Error Messages :");
Label lbl_errorMsg = toolkit.createLabel(group_error, "345", SWT.CENTER);
Font errorFont = new Font(lbl_errorMsg.getDisplay(), new FontData("Arial", 13, SWT.BOLD));
lbl_errorMsg.setFont(errorFont);
lbl_errorMsg.pack();
sectionA.setClient(sectionClientA);
}
Use the GridLayout and set the columns equal width:
Composite dynamicDataComp = new Composite(parent, SWT.NONE);
dynamicDataComp.setLayout(new GridLayout(3, true));
dynamicDataComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Group group_incom = new Group(dynamicDataComp, SWT.NONE);
group_incom.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
group_incom.setLayout(new RowLayout());
//...
One way is to use GridLayout for the parent composite and tell it use 3 equal sized columns:
Composite dynamicDataComp = toolkit.createComposite(sectionClientA);
dynamicDataComp.setLayout(new GridLayout(3, true));
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.
I would like to have a resizable text area in one of my Eclipse Plugins. It should have a gripper on the lower right corner that can be dragged to change the size of the text area, similar to following html example:
<!DOCTYPE html>
<html>
<body>
<textarea rows="4" cols="50">
This is a resizable html text area with a gripper at the lower right corner. How to create something similar with SWT JFace?</textarea>
</body>
</html>
Result as static image:
I am already able to create an SWT multi-line text:
Text textArea = toolkit.createText(parentContainer, "Default text", SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
textArea.setEnabled(isEnabled());
textArea.setToolTipText("tooltip");
GridData areaData = new GridData();
areaData.grabExcessHorizontalSpace = true;
areaData.horizontalAlignment = GridData.FILL;
areaData.verticalAlignment = GridData.FILL;
areaData.grabExcessVerticalSpace = true;
areaData.heightHint = 80;
areaData.widthHint = 200;
textArea.setLayoutData(areaData);
Instead of the scroll bar I would like to have a gripper that is able to resize the text field vertically and horizontally.
The documentation for the Text element is here and I could not find a gripper option:
http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fwidgets%2FText.html
How can I add a gripper to the text?
Is there a resizable panel with a gripper that I can use to wrap the text?
A "Sash" only seems to be resizable in one direction:
Can you create a resizable control in SWT?
Is there a finished control that provides the functionality I am looking for? (I had a look at the nebula widgets but there does not seem to be a text area component with gripper.)
With the help of Baz I found following solution. Its not perfect but kind of working and may be useful as a starting point for others. Please not that the parent layout does not yet adapt to the new size. And the example below does not yet set min values for the rect sizes.
//toolkit
FormToolkit toolkit = new FormToolkit(Display.getCurrent());
//create content composite for label, text area and gripper
contentContainer = toolkit.createComposite(parent);
GridData fillHorizontal = new GridData();
fillHorizontal.grabExcessHorizontalSpace = true;
fillHorizontal.horizontalAlignment = GridData.FILL;
contentContainer.setLayoutData(fillHorizontal);
GridLayout gridLayout = new GridLayout(1, true);
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 2;
gridLayout.marginHeight = 2;
gridLayout.marginWidth = 0;
contentContainer.setLayout(gridLayout);
//label
String currentLabel = getLabel();
toolkit.createLabel(contentContainer, currentLabel);
//text area
textArea = toolkit.createText(contentContainer, get(), SWT.MULTI | SWT.BORDER | SWT.WRAP);
textArea.setEnabled(isEnabled());
textArea.setToolTipText(tooltip);
GridData areaData = new GridData();
areaData.grabExcessHorizontalSpace = true;
areaData.grabExcessVerticalSpace = true;
areaData.horizontalAlignment = GridData.FILL;
areaData.verticalAlignment = GridData.FILL;
areaData.widthHint = 200;
areaData.heightHint = 80;
textArea.setLayoutData(areaData);
//gripper
org.eclipse.swt.widgets.Label gripper = toolkit.createLabel(contentContainer, "");
gripper.setImage(Activator.getImage("tracker.png"));
GridData tragData = new GridData();
tragData.horizontalAlignment = GridData.END;
gripper.setLayoutData(tragData);
Listener trackerListener = new Listener() {
#Override
public void handleEvent(Event e) {
Tracker tracker = new Tracker(contentContainer.getParent(), SWT.RESIZE | SWT.DOWN | SWT.RIGHT);
Rectangle maxRect = contentContainer.getParent().getBounds();
Rectangle rect = contentContainer.getBounds();
tracker.setRectangles(new Rectangle[] { rect });
if (tracker.open()) {
Rectangle after = tracker.getRectangles()[0];
Rectangle newRect = new Rectangle(
after.x,
after.y,
Math.min(after.width, maxRect.width - 10),
Math.min(after.height, maxRect.height - 10));
contentContainer.setBounds(newRect);
}
tracker.dispose();
}
};
gripper.addListener(SWT.MouseDown, trackerListener);
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);