Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » [SWT, RAP]: scrolled composite inside a tabFolder
[SWT, RAP]: scrolled composite inside a tabFolder [message #655078] Fri, 18 February 2011 09:33 Go to next message
Gabriele  is currently offline Gabriele Friend
Messages: 19
Registered: November 2010
Junior Member
Hi guys,
recently I have a lot of problems when I try to put a scrolled composite (functioning) inside a tabItem of a tabFolder.
I create a snippet for what I'm doing, using exsisting functioning SWT snippets:

public class SimulateView_ScrolledTabFolder {

	static public void main(String [] args){
		Display display = new Display ();
		final Shell shell = new Shell (display);
		
		shell.setLayout(new GridLayout());
		
		final TabFolder tabFolder = new TabFolder (shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
			TabItem item = new TabItem (tabFolder, SWT.NONE);
			item.setText ("TabItem ");
		
		final ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		Composite c = new Composite(sc, SWT.NONE);
		c.setLayout(new GridLayout(10, true));
		for (int i = 0 ; i < 500; i++) {
			Button b = new Button(c, SWT.PUSH);
			b.setText("Button "+i);
		}
		sc.setContent(c);
		sc.setExpandHorizontal(true);
		sc.setExpandVertical(true);

		sc.setShowFocusedControl(true);
		item.setControl(sc);
		shell.setSize(300, 500);
		
		Rectangle ca = shell.getClientArea();
		tabFolder.setSize(300, 500);
		
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}


In particular it is a composition between the Snippet188 (for ScrolledComposite) and Snippet76 (for TabFolder).
I want a scrolledComposite working inside a TabFolder, but as in the given snippet, it works like the SC even exists. Maybe I missed something simple, but till now I haven't find a solution.
I appreciate any help

Thanks you guys for any future advice.

Gabriele
Re: [SWT, RAP]: scrolled composite inside a tabFolder [message #655096 is a reply to message #655078] Fri, 18 February 2011 10:11 Go to previous messageGo to next message
Gabriele  is currently offline Gabriele Friend
Messages: 19
Registered: November 2010
Junior Member
Hi guys,
it's still me!!
I have found a possible solution to my snippet and I will post my solution:

package org.eclipse.swt.snippets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

public class SimulateView_ScrolledTabFolder {

	static public void main(String [] args){
		Display display = new Display ();
		final Shell shell = new Shell (display);
		
		shell.setLayout(new GridLayout());
		
		final TabFolder tabFolder = new TabFolder (shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
			TabItem item = new TabItem (tabFolder, SWT.NONE);
			item.setText ("TabItem ");
		
		final ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		sc.setLayoutData(new GridData());
		Composite c = new Composite(sc, SWT.NONE);
		c.setLayout(new GridLayout(10, true));
		for (int i = 0 ; i < 500; i++) {
			Button b = new Button(c, SWT.PUSH);
			b.setText("Button "+i);
		}
		sc.setContent(c);
		sc.setExpandHorizontal(true);
		sc.setExpandVertical(true);
		sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		sc.setShowFocusedControl(true);
		item.setControl(sc);
		shell.setSize(300, 500);
		
		Rectangle ca = shell.getClientArea();
		tabFolder.setSize(ca.width-20, ca.height-20);
		
		tabFolder.addControlListener(new ControlAdapter() {
			public void controlResized(ControlEvent e) {
				Rectangle r = shell.getClientArea();
				tabFolder.setSize(r.width-20, r.height-20);
			}
		});
		
		System.out.println("tabFolder.computeSize" + tabFolder.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		System.out.println("tabFolder.getSize" + tabFolder.getSize());
		System.out.println("sc.computeSize" + sc.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		System.out.println("sc.getSize" + sc.getSize());
		System.out.println("shell.computeSize" + shell.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		System.out.println("shell.getSize" + shell.getSize());
		System.out.println("shell.getClientArea" + shell.getClientArea());
		
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}


This timethe problem is solved. Moreover, the tabFolder listen to resize of the window and it resizes itself accordingly.
I hope to be of some help to someone.
If you have alternative solution, feel free to reply

Good work to everybody!!
Gabriele
Re: [SWT, RAP]: scrolled composite inside a tabFolder [message #655285 is a reply to message #655096] Fri, 18 February 2011 23:11 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Hi Gabriele,

I think there are a few issues in your code:

* Setting the size of the tab folder is not effective because its size is
managed by a layout.

* There's a resize listener on the tab folder that tries to modify the
size of the tab folder itself. This won't do anything useful.

The code below should suffice for your case:

Shell shell = new Shell( display );
shell.setLayout( new FillLayout() );
final TabFolder tabFolder = new TabFolder( shell, SWT.BORDER );
TabItem item = new TabItem( tabFolder, SWT.NONE );
item.setText( "TabItem " );
ScrolledComposite sc = new ScrolledComposite( tabFolder, SWT.BORDER |
SWT.H_SCROLL | SWT.V_SCROLL );
Composite c = new Composite( sc, SWT.NONE );
c.setLayout( new GridLayout( 10, true ) );
for( int i = 0; i < 500; i++ ) {
Button b = new Button( c, SWT.PUSH );
b.setText( "Button " + i );
}
sc.setContent( c );
sc.setExpandHorizontal( true );
sc.setExpandVertical( true );
sc.setMinSize( c.computeSize( SWT.DEFAULT, SWT.DEFAULT ) );
sc.setShowFocusedControl( true );
item.setControl( sc );

HTH, Ralf

--
Ralf Sternberg

Twitter: @ralfstx
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: [SWT, RAP]: scrolled composite inside a tabFolder [message #655450 is a reply to message #655285] Mon, 21 February 2011 08:22 Go to previous message
Gabriele  is currently offline Gabriele Friend
Messages: 19
Registered: November 2010
Junior Member
Hi Ralf,
thank you for you reply, I really appreciate it.

I have used your suggestion and it works.
Now, if I want to manage the size of the tabFolder by myself, I saw that I have to delete the setLayout line on the Shell.

However, thanks again
Previous Topic:RAP Theming CSS: How to Table-Cell style-type?
Next Topic:Launch new window from a view
Goto Forum:
  


Current Time: Fri Apr 26 09:10:58 GMT 2024

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

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

Back to the top