Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MutiText Input selection using JFACE with the help of + button

 
Piu Bhattacharya
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to JFACE and was designing a multitext input in the following way.

composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_BOTH));

Label sampletext1=new Label(composite,SWT.NONE);
sampletext1.setText("Provide The names");
sampletext1.setForeground(darkmagenta);
sampletext1.setFont(boldFont);
names= new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL );

names.setLayoutData(new GridData(GridData.FILL_BOTH));
and it is working fine.

However I wanted to know if I could add a multi user input using a + button. Say a user inputs a name , then if he has one more name to add , he clicks on the + button and another text area opens for him below.

I searched online for this and I found out a suggestion
to add a selection listener on the button that invokes a method that creates a new Composite inside the parent Composite and pack the outermost container (Shell) after the new container is added.

This is the code I am working on now:

button.addSelectionListener(new SelectionListener() {

public void widgetSelected(SelectionEvent event) {

Display.add(createCustomArea(c));
composite1.pack();

}

And this is my createCustom Area method looks something like this:

private Composite createCustomArea(Composite c) {

Composite inner = new Composite(c, SWT.NONE);
inner.setLayout(new GridLayout(2, false));
inner.setLayoutData(new GridData(GridData.FILL, GridData.END, true, false));

GridData gd = new GridData(SWT.FILL, SWT.FILL, true,true);

Label l = new Label(inner, SWT.NONE);
l.setText("Label #" + lCount++);
l.setLayoutData(gd);

Text t = new Text(inner, SWT.NONE);
t.setLayoutData(gd);
return inner;
}

I am having difficulty in this line [ Display.add(createCustomArea(c));]
On how to call the createCustomArea from the buttonlistener

Any help/comments would be welcome.

Cheers,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic