aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes MutiText Input selection using JFACE with the help of + button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "MutiText Input selection using JFACE with the help of + button" Watch "MutiText Input selection using JFACE with the help of + button" New topic
Author

MutiText Input selection using JFACE with the help of + button

Piu Bhattacharya
Greenhorn

Joined: Jun 20, 2013
Posts: 1
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,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MutiText Input selection using JFACE with the help of + button