This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem creating a dynamic form with SWT

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I am facing a problem while making a dynamic form.

What I am trying to do is to make a part of the form dynamic, i.e. it can have different controls depending upon the content available.

If an image is available, then we have to display the image and the associated information. If the image is not available, then we have to display only the information, and no image will be displayed.

I am using the following code as my basis :

mport org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Test {

static int pageNum = 0;
static Composite pageComposite;

public static void main(String args[]) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
Button button = new Button(shell, SWT.PUSH);
button.setText("Push");
pageComposite = new Composite(shell, SWT.NONE);
pageComposite.setLayout(new GridLayout());
pageComposite.setLayoutData(new GridData());

button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if ((pageComposite != null) && (!pageComposite.isDisposed())) {
pageComposite.dispose();
}
pageComposite = new Composite(shell, SWT.NONE);
pageComposite.setLayout(new GridLayout());
pageComposite.setLayoutData(new GridData());
if (pageNum++ % 2 == 0) {
Table table = new Table(pageComposite, SWT.BORDER);
table.setLayoutData(new GridData());
for (int i = 0; i < 5; i++) {
new TableItem(table, SWT.NONE).setText("table item "
+ i);
}
} else {
new Button(pageComposite, SWT.RADIO).setText("radio");
}
shell.layout(true);
}
});

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

which displays contents correctly, while in my example :

--------testArea = new Composite(shell, SWT.BORDER);
--------testArea.setLayout(new GridLayout());
--------GridData testAreaData = new GridData(GridData.FILL_BOTH);
--------testAreaData.grabExcessVerticalSpace = true;
--------testAreaData.grabExcessHorizontalSpace = true;
--------testAreaData.horizontalSpan = 9;
--------testArea.setLayoutData(testAreaData);

Here's the code for the button which when clicked should generate the dynamic content.

--------startTestButton.addSelectionListener(new SelectionListener(){

------------@Override
------------public void widgetDefaultSelected(SelectionEvent e) {
----------------// TODO Auto-generated method stub
----------------
------------}

------------@Override
------------public void widgetSelected(SelectionEvent e) {
----------------Control children[] = testArea.getChildren();
------------------------for(Control c:children){
---------------------------c.dispose();
------------------------}
----------------Button b = new Button(testArea, SWT.RADIO);
----------------b.setText("radio");
----------------shell.layout(true);
------------}
------------
--------});

I don't know what I am doing wrong here, but I am not able to see the dynamic button on the screen.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic