How to replace a button and re position it dynamically? - swt

I have a text box and a add button next to it, when I click on add button I am able to add a text box and delete button next to it. Now I want the add button on the first row to be changed to delete and the add button should be re-positioned below two rows, when the second row delete button is clicked (the second row is deleted )the add button should go back to the first row and replace delete button. It should look like following.
How do I achieve this?

If you create a Composite as a container of sorts, you can add and remove from it allowing everything outside to remain in the correct order. By reserving the space, the delete button is always below the contents of the container.
I have a text box and a add button next to it, when I click on add button I am able to add a text box and delete button next to it
For example, if we have a small Shell with an add Button as you mentioned, and an empty space to add the Text widgets to:
final Composite baseComposite = new Composite(shell, SWT.BORDER);
baseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
baseComposite.setLayout(new GridLayout());
final Composite rowsContainerComposite = new Composite(baseComposite, SWT.BORDER);
rowsContainerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
rowsContainerComposite.setLayout(new GridLayout());
final Button addButton = new Button(baseComposite, SWT.PUSH);
addButton.setText("Add");
(For now the empty space is grabbing all available space, but you can change that as needed)
When adding rows, you can add to the rowsContainerComposite:
addButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(final SelectionEvent e) {
new Row(rowsContainerComposite);
rowsContainerComposite.layout();
}
});
A sample Row class:
public class Row {
final Composite baseComposite;
public Row(final Composite parent) {
baseComposite = new Composite(parent, SWT.BORDER);
baseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
baseComposite.setLayout(new GridLayout(2, false));
final Text text = new Text(baseComposite, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final Button deleteButton = new Button(baseComposite, SWT.PUSH);
deleteButton.setText("Delete");
deleteButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(final SelectionEvent e) {
baseComposite.dispose();
parent.layout();
}
});
}
}
when the second row delete button is clicked (the second row is deleted )the add button should go back to the first row
Then when deleted, rows will shift back appropriately:
the add button should be re-positioned below two rows
The idea is that by using the "container" composite, you're reserving that space to add and remove the rows from. The delete button will always be below the rows as they are added and removed.
Full example:
public class AddDeleteButtonTest {
private static class Row {
final Composite baseComposite;
public Row(final Composite parent) {
baseComposite = new Composite(parent, SWT.BORDER);
baseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
baseComposite.setLayout(new GridLayout(2, false));
final Text text = new Text(baseComposite, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final Button deleteButton = new Button(baseComposite, SWT.PUSH);
deleteButton.setText("Delete");
deleteButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(final SelectionEvent e) {
baseComposite.dispose();
parent.layout();
}
});
}
}
private final Display display;
private final Shell shell;
public AddDeleteButtonTest() {
display = new Display();
shell = new Shell(display);
shell.setLayout(new FillLayout());
final Composite baseComposite = new Composite(shell, SWT.BORDER);
baseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
baseComposite.setLayout(new GridLayout());
final Composite rowsContainerComposite = new Composite(baseComposite, SWT.BORDER);
rowsContainerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
rowsContainerComposite.setLayout(new GridLayout());
final Button addButton = new Button(baseComposite, SWT.PUSH);
addButton.setText("Add");
addButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(final SelectionEvent e) {
new Row(rowsContainerComposite);
rowsContainerComposite.layout();
}
});
}
public void run() {
shell.setSize(200, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(final String... args) {
new AddDeleteButtonTest().run();
}
}

I did the same in one of my project. The code is bit complicated to do in Jface/SWT. Adding and removing widgets on composite will be bit heavy task. This will reduce UI performance.
If you use Jface tableviewer instead of creating composite, you will get better UI performance and good look as well. In table viewer in one column you can show textboxes and in one column you can show buttons. You can write table column Editing support/label providers to show the buttons.
With this approach you will be able show buttons for all rows or when you click on any cell you want to add or delete.
I can't share the code snippet right now, due to some reasons, but if you need I will share it on weekends

Related

How to create a text box when click on button in swt?

I have created 2 composite in swt. 1 button created inside 1st composite. I want to create one text box when I will click on the button. But I am unable to do that functionality.
Assuming you are using layouts for your code you just need to create the Text control and then redo the layout.
For example, using GridLayout:
shell.setLayout(new GridLayout());
final Composite buttonComposite = new Composite(shell, SWT.NONE);
buttonComposite.setLayout(new GridLayout());
final Button button = new Button(buttonComposite, SWT.PUSH);
button.setText("Create Text");
final Composite textComposite = new Composite(shell, SWT.NONE);
textComposite.setLayout(new GridLayout());
button.addSelectionListener(new SelectionAdapter()
{
#Override
public void widgetSelected(final SelectionEvent e)
{
final Text newText = new Text(textComposite, SWT.SINGLE | SWT.BORDER);
newText.setText("New text control");
newText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
// Update the layout
shell.layout(true);
}
});
Alternatively you can create the Text control at the beginning but make it not visible and exclude it from the layout:
shell.setLayout(new GridLayout());
final Composite buttonComposite = new Composite(shell, SWT.NONE);
buttonComposite.setLayout(new GridLayout());
final Button button = new Button(buttonComposite, SWT.PUSH);
button.setText("Create Text");
final Composite textComposite = new Composite(shell, SWT.NONE);
textComposite.setLayout(new GridLayout());
final Text newText = new Text(textComposite, SWT.SINGLE | SWT.BORDER);
newText.setText("New text control");
// Not visible
newText.setVisible(false);
// Exclude from layout
final GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
data.exclude = true;
newText.setLayoutData(data);
button.addSelectionListener(new SelectionAdapter()
{
#Override
public void widgetSelected(final SelectionEvent e)
{
// Include in layout
final GridData data = (GridData)newText.getLayoutData();
data.exclude = false;
// Make visible
newText.setVisible(true);
// Redo layout
shell.layout(true);
}
});

SWT - How to change the size of Text box dynamically

I am trying to create a Simple UI which contains a combo, a text box and a browse button. The combo will be containing two values: Execution Times and Execute with File.
When the Execution Times option is selected, the combo box followed by a text box should be displayed.
when the Execute with File option is selected, the combo box, a text box, and a browse button should be displayed.
When I am switching between these options, the widgets are not getting aligned properly. Refer to the below image. The text box size is not getting expanded to the available space.
public class TestUI {
public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout(1, true));
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new GridLayout(3, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
Combo combo = new Combo(composite, SWT.READ_ONLY);
String[] input = { "Execution Times", "Execute with File" };
combo.setItems(input);
Text loopText = new Text(composite, SWT.SINGLE | SWT.BORDER);
GridData gridData = new GridData(SWT.BEGINNING | GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
loopText.setLayoutData(gridData);
loopText.setEnabled(false);
Button browseButton = new Button(composite, SWT.PUSH);
browseButton.setText("Browse...");
browseButton.setVisible(false);
combo.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
String text2 = combo.getText();
System.out.println(text2);
if (text2.equals("Execution Times")) {
loopText.setEnabled(true);
loopText.setText("1");//$NON-NLS-1$
GridData gridData1 = new GridData(SWT.BEGINNING, SWT.TOP, false, false);
gridData1.grabExcessHorizontalSpace = true;
gridData1.horizontalSpan = 2;
loopText.setLayoutData(gridData1);
browseButton.setVisible(false);
loopText.getParent().layout();
}
if (text2.equals("Execute with File")) {
GridData gridData1 = new GridData(SWT.BEGINNING, SWT.TOP, false, false);
gridData1.grabExcessHorizontalSpace = true;
loopText.setLayoutData(gridData1);
gridData.exclude= false;
browseButton.setVisible(true);
browseButton.setFocus();
loopText.setText("");
loopText.setEnabled(false);
loopText.getParent().layout();
}
}
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Can any one help me on this?
From what I understand, depending on the combo selection, the text field and text field plus button serve different purposes:
when Execution Times is selected, the number of times is to be entered
otherwise Execute with File requires a file name to be entered or browsed for
Therefore, I would use a Composite next to the combo widget to hold either a text field to enter a number (or even a Spinner) or a text field and button to enter/select a file name.
Composite composite = new Composite( parent, SWT.NONE );
Text executionTimesText = new Text( composite, SWT.BORDER );
composite.setLayout( new StackLayout() );
Composite executionFileComposite = new Composite( composite, SWT.NONE );
// use a GridLayout to position the file name text field and button within the executionFileComposite
combo.addListener( SWT.Selection, event -> {
StackLayout layout = ( StackLayout )composite.getLayout();
if( combo.getSelectionIndex() == 0 ) {
layout.topControl = executionTimesText;
} else if( combo.getSelectionIndex() == 1 ) {
layout.topControl = executionFileComposite;
}
composite.layout();
}
The StackLayout allows you to stack the different input fields and switch betwen them as needed (i.e. according to the combo's selection).
For starters, you don't need to recreate the GridData for the Text widget every time. Instead, just modify the original via gridData.horizontalSpan, or if in practice you don't have access to the GridData instance, you can get at it via ((GridData) gridData.getLayoutData()).horizontalSpan, etc.
The reason you're seeing the blank space at the bottom of the Shell is because you've created a layout with 3 columns, and then added the following:
The Combo
The Text (with horizontalSpan set to 2, so this uses 2 columns)
The Button
The Combo and the Text take up all 3 columns, so a new row is added for the Button. Then you call pack(), and the preferred size is calculated, which will be for 2 rows, and the first row only sized for 2 widgets.
Instead of calling pack() and shrinking the size of the Shell down to the preferred size, we can just set a size on the Shell via Shell.setSize(...). In general you don't want to mix setSize(...) and layouts, but you've tagged your post with "RCP", so your Shell will already have a size and you won't be manually calling pack() and open().
Full example:
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(300, 80);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout(1, true));
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new GridLayout(3, false));
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final Combo combo = new Combo(composite, SWT.READ_ONLY);
String[] input = {"Execution Times", "Execute with File"};
combo.setItems(input);
final Text loopText = new Text(composite, SWT.SINGLE | SWT.BORDER);
final GridData textGridData = new GridData(SWT.FILL, SWT.FILL, true, false);
textGridData.horizontalSpan = 2;
loopText.setLayoutData(textGridData);
loopText.setEnabled(false);
final Button browseButton = new Button(composite, SWT.PUSH);
browseButton.setText("Browse...");
browseButton.setVisible(false);
combo.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
String text2 = combo.getText();
System.out.println(text2);
if (text2.equals("Execution Times")) {
loopText.setEnabled(true);
loopText.setText("1");
// Can also do ((GridData) textGridData.getLayoutData())...
textGridData.grabExcessHorizontalSpace = true;
textGridData.horizontalSpan = 2;
browseButton.setVisible(false);
loopText.getParent().layout();
}
if (text2.equals("Execute with File")) {
loopText.setEnabled(false);
loopText.setText("");
textGridData.grabExcessHorizontalSpace = true;
textGridData.horizontalSpan = 1;
browseButton.setVisible(true);
browseButton.setFocus();
loopText.getParent().layout();
}
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
Alternatively, if you are actually creating and opening a new Shell, then call pack() (to get the preferred size) prior to making the Text widget take up two columns:
shell.pack();
// Move these two lines down to the end
textGridData.horizontalSpan = 2;
browseButton.setVisible(false);
shell.layout(true, true);
shell.open();
What we've done is add all 3 widgets without adjusting the horizontalSpan. Then, call pack() to set the size of the Shell assuming that all 3 widgets appear in a single row. After calling pack(), set the horizontalSpan to 2, and hide the Button. When the Shell is opened, you will see:

Eclipse JFace/SWT ViewerFilter select never gets called

I'm trying to build a simple dialog with a TableViewer in it, along with a checkbox which would filter the data. However the table is empty and the filtering never gets done. Whats wrong with this code?
public class AsTestDialog extends TitleAreaDialog {
private Table table;
private AsTestFilter filter;
private TableViewer tableViewer;
public AsTestDialog(Shell parentShell) {
super(parentShell);
}
#Override
public void create() {
super.create();
setTitle("Table Test");
}
#Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
area.setLayout(new GridLayout(1, false));
tableViewer = new TableViewer(area, SWT.BORDER | SWT.FULL_SELECTION);
table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmnNewColumn = tableViewerColumn.getColumn();
tblclmnNewColumn.setWidth(130);
tblclmnNewColumn.setText("Column1");
TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmnId = tableViewerColumn_2.getColumn();
tblclmnId.setWidth(150);
tblclmnId.setText("Column2");
Composite composite = new Composite(area, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
Button btnFilter = new Button(composite, SWT.CHECK);
btnFilter.setBounds(10, 10, 111, 20);
btnFilter.setText("Filter");
btnFilter.addSelectionListener(new SelectionListener() {
#Override
public void widgetSelected(SelectionEvent e) {
System.out.println("CHECKBOX SELECTED");
filter.setFilterType("foobar");
tableViewer.refresh();
}
#Override
public void widgetDefaultSelected(SelectionEvent e) {}
});
addTestData(table);
//Filter
filter = new AsTestFilter();
tableViewer.addFilter(filter);
tableViewer.getTable().pack();
tableViewer.refresh();
return area;
}
private void addTestData(Table table) {
TableItem item1 = new TableItem(table, SWT.NONE);
item1.setText(new String[] {"1","2"});
item1.setData("1");
TableItem item2 = new TableItem(table, SWT.NONE);
item2.setText(new String[] {"3","4"});
item2.setData("3");
}
}
The filter class:
public class AsTestFilter extends ViewerFilter {
private String filterType = "all";
public void setFilterType(String tp) {
this.filterType = tp;
}
#Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
System.out.println("SELECT CALLED: "+filterType);
return true;
}
}
If you are using the JFace TableViewer you must use a 'content provider' set with
tableViewer.setContentProvider(provider);
and then call
tableViewer.setInput(input data);
creating TableItem objects directly will not work properly as TableViewer expects to create these objects itself.
If you have a simple array or List of objects the content provider can simply be:
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
and the set input:
tableViewer.setInput(array or list);
Your filter is not called because you have not called setInput, the table viewer does nothing until this is called.
The ViewerFilter operates on the TableViewer's input, which will be null in your case as you aren't using tableViewer.setInput(model). Instead you are creating TableItems directly.
You will need to set up a content provider, label provider, and define a model which you can pass to .setInput for the table viewer, and remove the function which directly creates the TableItems.
Once you do this, the ViewerFilter should work.
There are plenty of tutorials around which describe this, including https://eclipse.org/articles/Article-Table-viewer/table_viewer.html and http://wiki.eclipse.org/index.php/JFaceSnippets

How to create a toolbar inside viewpart (Not use plugin.xml)

I Created a ToolItem "Save As" like image above, But it not display at toolbar position. So how to create a toolbar inside viewpart (Not use plugin.xml)
IMAGE EXAMPLE
This is my code Create Toolbar:
public void createToolbar(Composite parent) {
// Create composite Toolbar and set layout
toolBarComposite = new Composite(parent, SWT.NONE);
gridLayout = new GridLayout(1, false);
toolBarComposite.setLayout(gridLayout);
gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
toolBarComposite.setLayoutData(gridData);
// Create Toolbar
gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
toolBar = new ToolBar(toolBarComposite, SWT.FLAT);
toolBar.setLayoutData(gridData);
// Create Item
item = new ToolItem(toolBar, SWT.PUSH);
item.setImage(SAVE_IMAGE);
item.setToolTipText("Save (Ctrl + S)");
item.setEnabled(true);
item.addSelectionListener(new SelectionAdapter() {
private static final long serialVersionUID = -102212312093090431L;
#Override
public void widgetSelected(SelectionEvent e) {
}
#Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
Thank for your advance !
You're going to have to use contributions on the view site's action bar.
Example
// Copy-pasted from an existing project, so the code can be made nicer
private void createAdditionalToolbarActions()
{
getViewSite().getActionBars().getToolBarManager().add(new GroupMarker("additions")); //$NON-NLS-1$
getViewSite().getActionBars().getToolBarManager().prependToGroup("additions", new SaveAction()); //$NON-NLS-1$
getViewSite().getActionBars().updateActionBars();
}
The method getViewSite is part of ViewPart. Call this after the contents of the view have been created.
The SaveAction must implement IAction or IContributionItem. For convenience, just extend the SaveAction from org.eclipse.jface.action.Action and call methods such as setImageDescriptor and setToolTipText.
Do all your business login in the run override.

Avoid Tree Resize after Section expand

I've got a question I couldn't resolve myself for quite a while now.
I have a RCP ViewPage containing two sections. The sections are inside a SashForm so that the user is able to resize the expanded sections. In the bottom section there is a Tree which is empty after initialization. Through user interaction (i.e. removing a filter) the tree gets filled and has a lot of data in it. If the user now collapses the bottom view and expands it again the tree gets resized which causes ScrollBars in my form. What I want is scrollbars in the tree view.
Here is how the view is build:
- ScrolledForm
- Form Body
- Sash
- Section 1
- Composite
- Some View
- Section 2
- Composite
- Tree
I hope you understand what I'm trying to achieve.
UPDATE: Here is some source code to play with. It uses a Table instead of a tree but produces the same issue.
public class MyPersonPageEditor extends FormPage {
public static final String ID = "some.ID";
TableViewer tableViewer;
public MyPersonPageEditor(FormEditor editor) {
super(editor, ID, "Some Title");
}
#Override
protected void createFormContent(IManagedForm managedForm) {
FormToolkit toolkit = managedForm.getToolkit();
ScrolledForm form = managedForm.getForm();
Composite formBody = form.getBody();
formBody.setLayout(new GridLayout());
form.setText("Some Title");
toolkit.decorateFormHeading(form.getForm());
SashForm sfForm = new SashForm(formBody, SWT.VERTICAL);
sfForm.setLayout(new GridLayout());
sfForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Section topSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE);
topSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
topSection.setText("Section 1 Title");
Composite topSectionComposite = toolkit.createComposite(topSection);
topSectionComposite.setLayout(new GridLayout());
toolkit.createLabel(topSectionComposite, "Just some content. Doesn't need to be much");
Button btn = toolkit.createButton(topSectionComposite, "Create Table Content", SWT.PUSH);
btn.addSelectionListener(new SelectionListener() {
#Override
public void widgetSelected(SelectionEvent e) {
for (int i = 0 ; i < 10 ; i++) {
tableViewer.add("Element " + i);
}
}
#Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
topSection.setClient(topSectionComposite);
Section bottomSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE);
bottomSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
bottomSection.setText("Section 2 Title");
Composite bottomSectionComposite = toolkit.createComposite(bottomSection);
bottomSectionComposite.setLayout(new GridLayout());
bottomSectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
bottomSection.setClient(bottomSectionComposite);
Table table = toolkit.createTable(bottomSectionComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION |
SWT.V_SCROLL | SWT.H_SCROLL | SWT.RESIZE);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
table.setHeaderVisible(true);
tableViewer = new TableViewer(table);
tableViewer.add("New Element");
new TableColumn(table, SWT.LEFT).setText("Spalte 1");
TableLayout layoutDefault = new TableLayout();
layoutDefault.addColumnData(new ColumnWeightData(1));
table.setLayout(layoutDefault);
form.reflow(true);
}
}
If you click the button after start the table looks like the left picture. After you collapse and expand the second section it looks like the right one.
Here is the code that works: you just have to tweak the size of the Tree/Table and make sure it will not span across the vertical space:
public void createPartControl(Composite parent) {
FormToolkit toolkit = new FormToolkit(parent.getDisplay());
final ScrolledForm form = toolkit.createScrolledForm(parent);
Composite formBody = form.getBody();
formBody.setLayout(new GridLayout());
form.setText("Some Title");
toolkit.decorateFormHeading(form.getForm());
SashForm sfForm = new SashForm(formBody, SWT.VERTICAL);
sfForm.setLayout(new GridLayout());
sfForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
//top section
Section topSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE);
topSection.setLayout(new GridLayout());
topSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
topSection.setText("Section 1 Title");
Composite topSectionComposite = toolkit.createComposite(topSection);
topSectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
topSectionComposite.setLayout(new TableWrapLayout());
toolkit.createLabel(topSectionComposite, "Just some content. Doesn't need to be much");
Button btn = toolkit.createButton(topSectionComposite, "Create Table Content", SWT.PUSH);
btn.addSelectionListener(new SelectionListener() {
#Override
public void widgetSelected(SelectionEvent e) {
for (int i = 0 ; i < 10 ; i++) {
tableViewer.add("Element " + i);
}
form.reflow(true);
}
#Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
topSection.setClient(topSectionComposite);
//bottom section
Section bottomSection = new Section(sfForm, Section.TITLE_BAR | Section.EXPANDED | Section.TWISTIE);
bottomSection.setLayout(new GridLayout());
bottomSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
bottomSection.setText("Section 2 Title");
Composite bottomSectionComposite = toolkit.createComposite(bottomSection);
bottomSectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
bottomSectionComposite.setLayout(new TableWrapLayout());
Table table = toolkit.createTable(bottomSectionComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION |
SWT.V_SCROLL | SWT.H_SCROLL | SWT.RESIZE);
TableWrapData ttd222 = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB);
ttd222.maxHeight =200;
table.setLayoutData(ttd222);
table.setHeaderVisible(true);
tableViewer = new TableViewer(table);
tableViewer.add("New Element");
new TableColumn(table, SWT.LEFT).setText("Spalte 1");
TableLayout layoutDefault = new TableLayout();
layoutDefault.addColumnData(new ColumnWeightData(1));
table.setLayout(layoutDefault);
bottomSection.setClient(bottomSectionComposite);
form.reflow(true);
}
-make sure the Tree has the SWT.H_SCROLL style (if I remember correctly), that is has a minimum size (for example with GridLayout and GridData set the minHeight to X or with TableWrapLayout and TableData heightHint to X)
-if you don't manage to make it work just tell me and I'll try to make the code; also, a picture with the layout would be great