Following is my code:
Group leftGroup = new Group(parent, SWT.NONE);
leftListWidget = new org.eclipse.swt.widgets.List(leftGroup,
SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
leftListWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
From the above code I though that that if I added V_SCROLL AND H_SCROLL, it would add both horizontal and vertical scroll bar in my list widget. However I cannot see any scroll bar. When I increase the number of records in the list, it just increases the size (length) of the list.
Is it a problem with scrolling OR with setting the length of list widget?
This is the course of list in SWT!!!
You need to create your own widget (check i.e. http://www.snip2code.com/Snippet/11489/Custom-SWT-List-Box) and manage there you scrollable components.
Related
Hello Everyone,
I have 2 Groups and each group has 3 Label and Text combinations, as you can see from the above Image.
I would like the text field to grab as much as space possible.hence, I have used grab 'true' only for the text field.
These label and text fields are well aligned inside their own group/composite.
But, when these 2 Groups are considered as a whole, the label and text fields are out of alignment.
Is there a way to align these label and text fields across multiple Groups?
is there a way to align these labels and text fields, without declaring each groups having equal column width, and specifying the number of columns label and text fields occupy?
Below is the code I have used for creating the below groups.
private void createFirstGroup(Composite parent) {
Group firstGroup = new Group(parent, SWT.NONE);
firstGroup.setText("first group");
GridDataFactory.fillDefaults().grab(true, false).applyTo(firstGroup);
GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).applyTo(firstGroup);
String[] labels = new String[]{"Kwd","Variable","Value"};
for(int index=0;index<labels.length; index++){
Label label = new Label(firstGroup, SWT.NONE);
label.setText(labels[index]);
GridDataFactory.fillDefaults().applyTo(label);
Text textField = new Text(firstGroup, SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, false).applyTo(textField);
}
}
private void createSecondGroup(Composite parent) {
Group secondGroup = new Group(parent, SWT.NONE);
secondGroup.setText("second group");
GridDataFactory.fillDefaults().grab(true, false).applyTo(secondGroup);
GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).applyTo(secondGroup);
String[] labels = new String[]{"Count","Upper Comment","Lower Comment"};
for(int index=0;index<labels.length; index++){
Label label = new Label(secondGroup, SWT.NONE);
label.setText(labels[index]);
GridDataFactory.fillDefaults().applyTo(label);
Text textField = new Text(secondGroup, SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, false).applyTo(textField);
}
}
I would like to have some margin between text and icon (image) on my Button.
That's what I have:
Button btn = new Button(grpInventar, SWT.NONE);
GridData gd_btn = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
gd_btn.widthHint = 154;
btn.setLayoutData(gd_btn);
btn.setAlignment(SWT.LEFT);
btn.setImage(this.getImageByLocation(Application.getIconLocByInventoryClass(Whateverimage.class )));
btn.setText("Text");
I would love to add something like:
btn.setMarginBetweenTextIcon(12)
Is there something out there?
There is no support for this in SWT. You could use an image with empty pixels on the right or text with leading spaces.
Also note that not all platforms support having an image and text in a button.
How we can hide the SWT controls?
I know setVisible() method of control class can be used. But the disadvantage of it is, hidden widget will not released and can't be used by other widgets.
Is there any other approach which can be adopted?
You can use layout data. In case of GridLayout, you can use exclude specific widget from being drown on canvas.
Composite comp = new Composite(shell, SWT.NONE);
comp.setLayout(new GridLayout(4, false));
Label hidenLabel = new Label (comp, SWT.NONE);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
hidenLabel.setGridData(gridData );
//hide the button
gridData .exclude = true;
comp.pack();
I have a view that consists of a heading and a browser. I want the browser to fill my view. This is how it should look:
I have tried out different combinations.
c = new Composite(parent, SWT.NONE);
c.setLayout(new RowLayout(SWT.VERTICAL));
Label l = new Label(c, SWT.NONE);
l.setBackground(color);
l.setText("----------------------Heading--------------------------------");
l.setFont(new Font(null, new FontData(Constants.FONT, 12, SWT.BOLD)));
Composite wrapper = new Composite(c, SWT.NONE);
wrapper.setBackground(new Color(null, 0, 0, 0));
wrapper.setLayout(new FillLayout(SWT.VERTICAL));
browser = new Browser(wrapper, SWT.WRAP);
browser.setBackground(color);
produces:
Setting a FillLayout to c does not work either. By doing so both, heading and browser, share the view's size and have an equal size.
c = new Composite(parent, SWT.NONE);
c.setLayout(new FillLayout(SWT.VERTICAL));
Label l = new Label(c, SWT.NONE);
l.setBackground(color);
l.setText("----------------------Heading--------------------------------");
l.setFont(new Font(null, new FontData(Constants.FONT, 12, SWT.BOLD)));
browser = new Browser(c, SWT.WRAP);
browser.setBackground(color);
produces:
I have also tried the following:
composite with filllayout
-> composite with gridlayout
->composite with rowLayout (fixed height, grab right)
->composite with rowLayout
-> composite with fillLayout
-> composite with browser
Assuming that the header and browser have the same parent, you could use a GridLayout like this:
parent.setLayout( new GridLayout( 1, false ) );
label.setLayoutData( new GridData( SWT.FILL, SWT.TOP, true, false ) );
browser.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
Even though a one-cell-grid isn't really what a GridLayout is meant for, it should do the trick. The layout data advise the label to align at the top and use all horizontal space and the browser to use the horizontal and vertical space
I am using a jface tableviewer with a tablecolumnlayout (for it's parent composite) in my eclipse RCP application as follows -
Composite composite = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
GridDataFactory.swtDefaults().grab(true, true).applyTo(composite);
// Table Composite
Composite tblComposite = new Composite(composite, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(tblComposite);
GridDataFactory.swtDefaults().grab(true, true).hint(500, 180).applyTo(tblComposite);
// Table Column Layout
TableColumnLayout tableColumnLayout = new TableColumnLayout();
tblComposite.setLayout(tableColumnLayout);
tableViewer =
new TableViewer(tblComposite, SWT.BORDER | SWT.FULL_SELECTION |
SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.RESIZE);
Table table = tableViewer.getTable();
table.setLinesVisible(true);
table.setHeaderVisible(true);
GridDataFactory.fillDefaults().grab(true, true).applyTo(table);
// Column 1
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);
column.getColumn().setText("Source");
tableColumnLayout.setColumnData(column.getColumn(), new ColumnWeightData(50, true));
// Column 2
TableViewerColumn column2 = new TableViewerColumn(tableViewer, SWT.NONE);
column2.getColumn().setText("Target");
tableColumnLayout.setColumnData(column2.getColumn(), new ColumnWeightData(50, true));
tableViewer.setUseHashlookup(true);
tableViewer.setContentProvider(new ArrayContentProvider());
tableViewer.setLabelProvider(new CustomLabelProvider());
tableViewer.setSorter(new CustomViewSorter());
The problem I'm facing is that when I resize the window (reduce the size of the window) I'm not seeing Vertical and Horizontal scrollbars for the table viewer, that is even when the rows of the table are not seen when resizing (shrinking the size until some rows from table are hidden), the scrollbars don't appear at all but we generally expect them to appear right?
Is there anything wrong in GridData logic I have used? Please help me get unstuck here.
Remove SWT.FULL_SELECTION. It does not work with SWT.V_SCROLL | SWT.H_SCROLL.