Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Nested scrollable items?(Both parent control and List item are scrollable, but only parent control allows scrolling)
Nested scrollable items? [message #893262] Tue, 03 July 2012 11:54 Go to next message
Jasper Spaans is currently offline Jasper Spaans
Messages: 3
Registered: July 2012
Junior Member
I'm creating a plugin for eclipse, and using a Property page for some of it's settings.

The problem I'm faced with is that the property page contains (a couple of) lists that I want to have scrollable, but I can't seem to make that work.
Instead, (one of) the surrounding parent composit's is made scrollable.

I'm posting the parts of my program that I think are relevant here:

import org.eclipse.jface.preference.ColorFieldEditor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPropertyPage;

public class ContentPropertyPage extends org.eclipse.ui.dialogs.PropertyPage implements IWorkbenchPropertyPage {
	private String[] lstDataNames;
	private List dataNamesObject;
	private ColorFieldEditor dataNamesColorObject;

	@Override
	protected Control createContents(Composite parent) {

		
			  Composite myComposite = new Composite(parent, SWT.BORDER);
              myComposite.setLayout(new FillLayout());
              
              TabFolder maintabs = new TabFolder(myComposite,SWT.BORDER);

              Composite lst = makeTab(maintabs,"LST");
              lst.setLayout(new FillLayout());
              
              TabFolder subtabs = new TabFolder(lst,SWT.BORDER);
              
              lstDataNames = convert(getProperty(LST_DATANAMES));
              Composite comp = addTab(subtabs,"Data Names"); 
              dataNamesObject = addList(comp,lstDataNames);
              dataNamesColorObject = createPane(comp,LST_DATANAMES_COLOR,dataNamesObject);
              return myComposite;

	}
private List addList(Composite comp,String[] items){
		List lstList = new List(comp,SWT.V_SCROLL);
		lstList.setItems(items);
		return lstList;
	}
	private Composite addTab(TabFolder tabs, String tabName){
		Composite comp = makeTab(tabs,tabName);
		comp.setLayout(new GridLayout());
		return comp;
	}
	
	private Composite makeTab(TabFolder tabs,String tabName){
		TabItem tabItem = new TabItem(tabs, SWT.BORDER);
        tabItem.setText(tabName);
		Composite comp = new Composite(tabs,SWT.BORDER);

        tabItem.setControl(comp);
        return comp;
		
	}
	private ColorFieldEditor createPane(Composite shell,String color,final List list){
        
		GridLayout layout = new GridLayout(4, false);
		shell.setLayout(layout);

		list.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 5));

		Canvas can = new Canvas(shell,SWT.NONE);
		ColorFieldEditor colorEditor = new ColorFieldEditor(color,"Highlight Color",can);

		can.setLayoutData(new GridData(SWT.FILL,SWT.TOP,false,false,3,1));
		
		final Text newEntryText = new Text(shell, SWT.NONE);
		newEntryText.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false,2,1));
		
		Button b = new Button(shell, SWT.PUSH);
		b.setText("Add to List");
		b.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				list.add(newEntryText.getText(), list.getItemCount());
			}
		});
		b.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));

		b = new Button(shell, SWT.PUSH );

		b.setText("Remove Selection"); //$NON-NLS-1$
		b.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
					if(list.getSelectionIndex()>0){
				list.remove(list.getSelectionIndex());
				}
			}
		});
		b.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false, 1, 1));

		Label la = new Label(shell,SWT.NONE);
		la.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true,2,1));
		la = new Label(shell,SWT.NONE);
		la.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true,3,2));
		la = new Label(shell,SWT.NONE);
		la.setLayoutData(new GridData(SWT.LEFT,SWT.FILL,true,true,1,1));
				
		b = new Button(shell, SWT.PUSH);
		b.setText("Export List");
		b.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1));
		b = new Button(shell, SWT.PUSH);
		b.setText("Import List");
		b.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1));

		return colorEditor;
	}


Can anyone tell me what I'm doing wrong?
(also, if this is the wrong place to ask this, or you need more info, please tell me where to go/what to add)

edit: also providing screenshot of how it currently looks. Instead of the scrollbar on the right, the list should be shorter and have a scrollbar

[Updated on: Tue, 03 July 2012 11:58]

Report message to a moderator

Re: Nested scrollable items? [message #893282 is a reply to message #893262] Tue, 03 July 2012 13:02 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi Jasper,

to make your list scrollable you have to tell the parent layout how tall they preferably should be. Because by default it will try to set theirs size to theirs preferred size.
private List addList(Composite comp,String[] items){
    List lstList = new List(comp, SWT.V_SCROLL);
    lstList.setLayoutData(GridDataFactory.fillDefault().hint(SWT.DEFAULT, 80).create());
    lstList.setItems(items);
    return lstList;
}


Re: Nested scrollable items? [message #893287 is a reply to message #893282] Tue, 03 July 2012 13:12 Go to previous messageGo to next message
Jasper Spaans is currently offline Jasper Spaans
Messages: 3
Registered: July 2012
Junior Member
Thanks!

Unfortunately, that does not fix my problem.
Re: Nested scrollable items? [message #893298 is a reply to message #893287] Tue, 03 July 2012 13:36 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Well, maybe it's because you set the layout data in the createPane() again. Try to set height hint there and not in the addList().

[Updated on: Tue, 03 July 2012 13:44]

Report message to a moderator

Re: Nested scrollable items? [message #893311 is a reply to message #893298] Tue, 03 July 2012 14:05 Go to previous messageGo to next message
Jasper Spaans is currently offline Jasper Spaans
Messages: 3
Registered: July 2012
Junior Member
Yes! that's it....

I eventually changed it to:
GridData listGridData = new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 5);
		listGridData.heightHint = 300;
		list.setLayoutData(listGridData);


But that seems to do the trick.

I cannot believe how long it took me just to get myself to ask this here, and then to get the answer within the hour....
Re: Nested scrollable items? [message #893318 is a reply to message #893311] Tue, 03 July 2012 14:14 Go to previous message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Yeah, this forum is great if there is somebody who can give you the answer Smile
Previous Topic:autocomplete in ComboViewer
Next Topic:SWT OLE Excel windows
Goto Forum:
  


Current Time: Wed Oct 01 04:08:39 GMT 2014

Powered by FUDForum. Page generated in 0.02212 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software