Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » ScrolledComposite Question(Best implementation of ScrolledComposite to show a list of Composites)
ScrolledComposite Question [message #1827937] Wed, 27 May 2020 09:14 Go to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi
In a face dialog I want to show a list of items as composites. My current implementation seems to be incorrect: It only shows maximal 10 items, further items seem to be ignored. I looked now for a longer while for a solution without any success. Maybe someone may give me a hint. The code that builds the ui of the dialog looks like:
	@Override
	protected Control createDialogArea(final Composite parent)
	{
		this.setTitle();
		this.setMessage();

		Composite composite = new Composite(parent, SWT.BORDER);
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
		composite.setLayout(new GridLayout());

		Set<AddressGroup> extractedAddressGroups = extractAddressGroups(selection);
		if (extractedAddressGroups.size() > 1)
		{
			GridLayout layout = new GridLayout();
			layout.marginHeight = 0;
			layout.marginWidth = 0;
			layout.verticalSpacing = 0;

			GridData gridData = new GridData(GridData.FILL_BOTH);
			gridData.heightHint = 120;
			
			final ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.BORDER | SWT.SHADOW_ETCHED_IN | SWT.V_SCROLL);
			scrolledComposite.addListener(SWT.Resize, new Listener() 
			{
				@Override
				public void handleEvent(Event event) 
				{
					int width = scrolledComposite.getClientArea().width;
					scrolledComposite.setMinSize( parent.computeSize( width, SWT.DEFAULT ) );
				}
			});
			scrolledComposite.setLayout(layout);
			scrolledComposite.setLayoutData(gridData);

			layout = new GridLayout();
			layout.marginHeight = 0;
			layout.marginWidth = 0;
			layout.verticalSpacing = 0;

			gridData = new GridData(GridData.FILL_HORIZONTAL);
			//gridData.heightHint = extractedAddressGroups.size() * 46 + 20;

			Composite mainAddressGroupComposite = new Composite(scrolledComposite, SWT.BORDER);
			mainAddressGroupComposite.setLayout(layout);
			mainAddressGroupComposite.setLayoutData(gridData);

			AddressGroup[] addressGroups = extractedAddressGroups.toArray(new AddressGroup[0]);
			this.addressGroupLines = new ArrayList<AddressGroupLine>();
			for (int i = 0; i < addressGroups.length; i++)
			{
				Composite addressGroupComposite = new Composite(mainAddressGroupComposite, SWT.None);
				addressGroupComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
				addressGroupComposite.setLayout(new GridLayout(3, false));
				if (i == 0)
				{
					test = addressGroupComposite;
				}
				
				System.out.println(this.addressGroupLines.add(new AddressGroupLine(i, addressGroupComposite, addressGroups[i])));
			}
			scrolledComposite.setContent(mainAddressGroupComposite);
			scrolledComposite.setExpandHorizontal(true);
			scrolledComposite.setExpandVertical(true);
			scrolledComposite.pack();
		}
		
		if (EditorSelector.values()[PersonSettings.getInstance().getEditorSelector()]
				.equals(EditorSelector.MULTI_PAGE_EDITOR))
		{
			GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
			gridData.horizontalSpan = 2;

			collectionSelector = new Button(composite, SWT.CHECK);
			collectionSelector.setText("Gruppenadressen nur einmal auflisten");
			collectionSelector.setLayoutData(gridData);
		}

		Label label = new Label(composite, SWT.None);
		label.setLayoutData(new GridData());
		label.setText("Sortierung");

		DataMapKey[] keys = this.getSortKeys();
		Combo combo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
		combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		sortViewer = new ComboViewer(combo);
		sortViewer.setContentProvider(new ArrayContentProvider());
		sortViewer.setLabelProvider(new LabelProvider()
		{
			@Override
			public String getText(Object element)
			{
				if (element instanceof DataMapKey)
				{
					DataMapKey key = (DataMapKey) element;
					return key.getName();
				}
				return "";
			}
		});
		sortViewer.setInput(this.getSortKeys());
		sortViewer.setSelection(new StructuredSelection(new DataMapKey[] { keys[0] }));

		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
		gridData.horizontalSpan = 2;
		
		shortList = new Button(composite, SWT.CHECK);
		shortList.setLayoutData(gridData);
		shortList.setText("Kurzliste");
		shortList.setSelection(settings.getBoolean("short.list.selected"));
		shortList.addSelectionListener(new SelectionListener() 
		{
			@Override
			public void widgetSelected(SelectionEvent e) 
			{
				settings.put("short.list.selected", shortList.getSelection());
				System.out.println(test.getBounds().height);
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) 
			{
				widgetSelected(e);
			}
		});
		
		gridData = new GridData(GridData.FILL_HORIZONTAL);
		gridData.horizontalSpan = 2;
		
		courseVisits = new Button(composite, SWT.CHECK);
		courseVisits.setLayoutData(gridData);
		courseVisits.setText("mit Kursteilnahmen");
		courseVisits.setSelection(settings.getBoolean("course.visits.selected"));
		courseVisits.addSelectionListener(new SelectionListener() 
		{
			@Override
			public void widgetSelected(SelectionEvent e) 
			{
				settings.put("course.visits.selected", courseVisits.getSelection());
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) 
			{
				widgetSelected(e);
			}
		});

		return parent;
	}


Thank you
Christian
Re: ScrolledComposite Question [message #1828249 is a reply to message #1827937] Thu, 04 June 2020 21:23 Go to previous messageGo to next message
Martin J is currently offline Martin JFriend
Messages: 50
Registered: August 2015
Member
Try this;

ScrollComposite scanvas = new ScrollComposite(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
Composite xcontainer = new Composite(scanvas, SWT.NONE);
scanvas.setContent(xcontainer);
// add your items to xcontainer with a suitable layout!
Re: ScrolledComposite Question [message #1828281 is a reply to message #1828249] Fri, 05 June 2020 13:59 Go to previous messageGo to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi Martin
I tried your code but it does not change anything. The V_SCROLL lets only scroll about 10 items, the rest stays invisible. Any idea?
thank you and regards Christian
Re: ScrolledComposite Question [message #1828293 is a reply to message #1828281] Sat, 06 June 2020 06:36 Go to previous messageGo to next message
Martin J is currently offline Martin JFriend
Messages: 50
Registered: August 2015
Member
If you add items after pack(), you may need to call scanvas.layout(). I have many of these. It works for me!
Re: ScrolledComposite Question [message #1828336 is a reply to message #1828293] Sun, 07 June 2020 20:25 Go to previous message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi Martin
I have found an (admittedly not elegant) solution by commenting out the code line gridData.heightHint=120; but now the dialog has the full height of the screen (not very nice, but all other solutions did not work.
Regards Christian
Previous Topic:Browser in Private mode
Next Topic:Code signature error: could not load SWT library in OS X Catalina
Goto Forum:
  


Current Time: Tue Apr 16 15:53:48 GMT 2024

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

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

Back to the top