Skip to main content



      Home
Home » Newcomers » Newcomers » Adding "Vertical ScrollBar" to a "TabFolder"
Adding "Vertical ScrollBar" to a "TabFolder" [message #267814] Sun, 18 January 2009 12:52 Go to next message
Eclipse UserFriend
hi everyone,Could anyone please tell as to how to add a V_Scroll or
H_Scroll to a tabfolder or to a tabitem??
Re: Adding "Vertical ScrollBar" to a "TabFolder" [message #267833 is a reply to message #267814] Mon, 19 January 2009 16:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 1/18/2009 12:52 PM, adithya wrote:
> hi everyone,Could anyone please tell as to how to add a V_Scroll or
> H_Scroll to a tabfolder or to a tabitem??
>
>

Did you try setting the child of the TabItem to a ScrolledComposite?
[using TabItem.setControl()]

Hope this helps,
Eric
Re: Adding "Vertical ScrollBar" to a "TabFolder" [message #267852 is a reply to message #267833] Tue, 20 January 2009 09:19 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the suggestion,but i also want to add WIDGETS(say Buttons
,Labels,etc..)

in the "TABITEMS"..and hence i will have to use setControl for that right??

Like i want to add "Labels" ,"Combo" boxes and others.My doubt is if i add
say more than the SIZE of the TABITEM which is visible on Display

(say only 3 labels and 3 combos are visible on the Tabitem on which i am
POPULATING the widgets)

then if i wish to add another pair of 'Label' and 'Combo' i want to add
that and view it using the SCROLL_BAR..i hope you are getting what i mean
right??not only 1 pair but say 5 or 10 pairs..

Also would like to tell there is not only a tabfolder on the "Shell"..I
have populated the SHELL with various TabFolders(There are 5 TabFolders
and i have done it using FormLayout)..Only this part i am not able to
tackle which i mentioned above..

I know you can surely help me out..Thanks..
Re: Adding "Vertical ScrollBar" to a "TabFolder" [message #267857 is a reply to message #267852] Tue, 20 January 2009 09:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 1/20/2009 9:19 AM, Eadith wrote:
> Thanks for the suggestion,but i also want to add WIDGETS(say Buttons
> ,Labels,etc..)
> in the "TABITEMS"..and hence i will have to use setControl for that right??
>
> Like i want to add "Labels" ,"Combo" boxes and others.My doubt is if i
> add say more than the SIZE of the TABITEM which is visible on Display
>
> (say only 3 labels and 3 combos are visible on the Tabitem on which i am
> POPULATING the widgets)

The ScrolledComposite can contain whatever other widgets you want; the
idea is to make the ScrolledComposite the child of the TabItem and let
it (ScrolledComposite) handle the scroll bars when/if necessary.
Just try it and see if it does what you want.

Also, please quote the original message when you are replying; other
people reading may not remember what was said before, so giving a quote
allows us all to keep the context of the discussion.

Eric
Re: Adding "Vertical ScrollBar" to a "TabFolder" [message #267898 is a reply to message #267857] Wed, 21 January 2009 11:19 Go to previous messageGo to next message
Eclipse UserFriend
Thanks a lot..i am able to add a SCROLLBAR to the TabItem..but there is a
method for "ScrollComposite" called "setContent(Control control)"

..hence, i am able to set the content to only ONE widget..

(say a Button)

Hence ,i tried setting the content to a GROUP(Composite object) and tried
adding the widgets to the GROUP object..but they aren't showing up on the
Group..

I am sending the code along with this reply..Could you please go through
it and solve my problems ..

Thanks..

import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

public class TabfolderScroll extends ApplicationWindow
{
public TabfolderScroll()
{
super(null);
}

protected Control createContents(Composite parent)
{

TabWidget TW = new TabWidget(parent);


parent.pack();
return parent;
}

public static void main(String args[])
{
TabfolderScroll TS = new TabfolderScroll();
TS.setBlockOnOpen(true);
TS.open();

Display.getCurrent().dispose();
}
}

class TabWidget extends Composite
{
public TabWidget(Composite parent)
{
super(parent,SWT.NONE);

GridLayout layout = new GridLayout(2,false);
setLayout(layout);


TabFolder TF = new TabFolder(this,SWT.TOP);
TF.setLayoutData(new GridData(GridData.FILL_BOTH));

TF.setBounds(10, 10, 200, 200);
TF.pack();
TabItem item1 = new TabItem(TF,SWT.NONE);



item1.setText("item 1");

item1.setControl(new Buttons(TF,item1));


}
}

class Buttons extends Composite
{
public Buttons(TabFolder tf,TabItem item)
{

super(tf,SWT.NONE);

GridLayout layout = new GridLayout(2,false);
setLayout(layout);

//Add Scrolled Composite to tabfolder
ScrolledComposite sc = new
ScrolledComposite(this,SWT.H_SCROLL|SWT.V_SCROLL);

//add Group to ScrolledComposite so as to add widgets to it.
Group g = new Group(sc,SWT.SHADOW_ETCHED_IN);
GridData gridsc = new GridData(GridData.FILL_BOTH);
sc.setLayoutData(gridsc);
System.out.println(tf.getBackground());

Color clr = tf.getBackground();
sc.setBackground(clr);
System.out.println(sc.getBackground());

//always show scroll bars
sc.setAlwaysShowScrollBars(true);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);

//set content to group which will contain widgets
sc.setContent(g);


for(int i=0;i<28;i++)
{
GridData gridb = new GridData(GridData.FILL_BOTH);

//add 28 combo boxes to group
Combo b = new Combo(g,SWT.PUSH);
b.setText("Button "+i);
b.setLayoutData(gridb);
b.setToolTipText("Button");

//b.pack();
}
}
}
Re: Adding "Vertical ScrollBar" to a "TabFolder" [message #267924 is a reply to message #267898] Wed, 21 January 2009 19:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 1/21/2009 11:19 AM, adithya wrote:
>
> Thanks a lot..i am able to add a SCROLLBAR to the TabItem..but there is
> a method for "ScrollComposite" called "setContent(Control control)"
>
> .hence, i am able to set the content to only ONE widget..
>
> (say a Button)
>
> Hence ,i tried setting the content to a GROUP(Composite object) and
> tried adding the widgets to the GROUP object..but they aren't showing up
> on the Group..
>
> I am sending the code along with this reply..Could you please go through
> it and solve my problems ..

Sorry, but I don't have time to review your code in detail (I get paid
to do that for my employer :-)
From a quick review, however, I can see two problems:
1) You don't set a layout on your Group. It looks like you want to use a
GridLayout there, but you never set one.
2) You can't share the same LayoutData object in multiple widgets; each
widget has to have its own instance. GridDataFactory can help make that
easy.

One more piece of advice: I STRONGLY recommend you read the
article/tutorial on using Layout managers in SWT - it is clear you don't
fully grasp how to use them and that article will help you understand:
http://www.eclipse.org/articles/article.php?file=Article-Und erstanding-Layouts/index.html

Eric



> import org.eclipse.jface.window.ApplicationWindow;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.ScrolledComposite;
> import org.eclipse.swt.graphics.Color;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Combo;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Control;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Group;
> import org.eclipse.swt.widgets.TabFolder;
> import org.eclipse.swt.widgets.TabItem;
>
> public class TabfolderScroll extends ApplicationWindow {
> public TabfolderScroll()
> {
> super(null);
> }
>
> protected Control createContents(Composite parent)
> {
>
> TabWidget TW = new TabWidget(parent);
>
>
> parent.pack();
> return parent;
> }
>
> public static void main(String args[])
> {
> TabfolderScroll TS = new TabfolderScroll();
> TS.setBlockOnOpen(true);
> TS.open();
>
> Display.getCurrent().dispose();
> }
> }
>
> class TabWidget extends Composite
> {
> public TabWidget(Composite parent)
> {
> super(parent,SWT.NONE);
>
> GridLayout layout = new GridLayout(2,false);
> setLayout(layout);
>
>
> TabFolder TF = new TabFolder(this,SWT.TOP);
> TF.setLayoutData(new GridData(GridData.FILL_BOTH));
>
> TF.setBounds(10, 10, 200, 200);
> TF.pack();
> TabItem item1 = new TabItem(TF,SWT.NONE);
>
>
>
> item1.setText("item 1");
>
> item1.setControl(new Buttons(TF,item1));
>
>
> }
> }
>
> class Buttons extends Composite
> {
> public Buttons(TabFolder tf,TabItem item)
> {
>
> super(tf,SWT.NONE);
>
> GridLayout layout = new GridLayout(2,false);
> setLayout(layout);
>
> //Add Scrolled Composite to tabfolder
> ScrolledComposite sc = new
> ScrolledComposite(this,SWT.H_SCROLL|SWT.V_SCROLL);
>
> //add Group to ScrolledComposite so as to add widgets to it.
> Group g = new Group(sc,SWT.SHADOW_ETCHED_IN);
> GridData gridsc = new GridData(GridData.FILL_BOTH);
> sc.setLayoutData(gridsc);
> System.out.println(tf.getBackground());
>
> Color clr = tf.getBackground();
> sc.setBackground(clr);
> System.out.println(sc.getBackground());
>
> //always show scroll bars
> sc.setAlwaysShowScrollBars(true);
> sc.setExpandHorizontal(true);
> sc.setExpandVertical(true);
>
> //set content to group which will contain widgets
> sc.setContent(g);
>
>
> for(int i=0;i<28;i++)
> {
> GridData gridb = new GridData(GridData.FILL_BOTH);
>
> //add 28 combo boxes to group
> Combo b = new Combo(g,SWT.PUSH);
> b.setText("Button "+i);
> b.setLayoutData(gridb);
> b.setToolTipText("Button");
>
> //b.pack();
> }
> }
> }
>
Re: Adding "Vertical ScrollBar" to a "TabFolder" [message #267949 is a reply to message #267924] Thu, 22 January 2009 09:05 Go to previous messageGo to next message
Eclipse UserFriend
Eric Rizzo wrote:

> On 1/21/2009 11:19 AM, adithya wrote:
>>
>> Thanks a lot..i am able to add a SCROLLBAR to the TabItem..but there is
>> a method for "ScrollComposite" called "setContent(Control control)"
>>
>> .hence, i am able to set the content to only ONE widget..
>>
>> (say a Button)
>>
>> Hence ,i tried setting the content to a GROUP(Composite object) and
>> tried adding the widgets to the GROUP object..but they aren't showing up
>> on the Group..
>>
>> I am sending the code along with this reply..Could you please go through
>> it and solve my problems ..

> Sorry, but I don't have time to review your code in detail (I get paid
> to do that for my employer :-)
> From a quick review, however, I can see two problems:
> 1) You don't set a layout on your Group. It looks like you want to use a
> GridLayout there, but you never set one.
> 2) You can't share the same LayoutData object in multiple widgets; each
> widget has to have its own instance. GridDataFactory can help make that
> easy.

> One more piece of advice: I STRONGLY recommend you read the
> article/tutorial on using Layout managers in SWT - it is clear you don't
> fully grasp how to use them and that article will help you understand:
>
http://www.eclipse.org/articles/article.php?file=Article-Und erstanding-Layouts/index.html

> Eric



>> import org.eclipse.jface.window.ApplicationWindow;
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.custom.ScrolledComposite;
>> import org.eclipse.swt.graphics.Color;
>> import org.eclipse.swt.layout.GridData;
>> import org.eclipse.swt.layout.GridLayout;
>> import org.eclipse.swt.widgets.Combo;
>> import org.eclipse.swt.widgets.Composite;
>> import org.eclipse.swt.widgets.Control;
>> import org.eclipse.swt.widgets.Display;
>> import org.eclipse.swt.widgets.Group;
>> import org.eclipse.swt.widgets.TabFolder;
>> import org.eclipse.swt.widgets.TabItem;
>>
>> public class TabfolderScroll extends ApplicationWindow {
>> public TabfolderScroll()
>> {
>> super(null);
>> }
>>
>> protected Control createContents(Composite parent)
>> {
>>
>> TabWidget TW = new TabWidget(parent);
>>
>>
>> parent.pack();
>> return parent;
>> }
>>
>> public static void main(String args[])
>> {
>> TabfolderScroll TS = new TabfolderScroll();
>> TS.setBlockOnOpen(true);
>> TS.open();
>>
>> Display.getCurrent().dispose();
>> }
>> }
>>
>> class TabWidget extends Composite
>> {
>> public TabWidget(Composite parent)
>> {
>> super(parent,SWT.NONE);
>>
>> GridLayout layout = new GridLayout(2,false);
>> setLayout(layout);
>>
>>
>> TabFolder TF = new TabFolder(this,SWT.TOP);
>> TF.setLayoutData(new GridData(GridData.FILL_BOTH));
>>
>> TF.setBounds(10, 10, 200, 200);
>> TF.pack();
>> TabItem item1 = new TabItem(TF,SWT.NONE);
>>
>>
>>
>> item1.setText("item 1");
>>
>> item1.setControl(new Buttons(TF,item1));
>>
>>
>> }
>> }
>>
>> class Buttons extends Composite
>> {
>> public Buttons(TabFolder tf,TabItem item)
>> {
>>
>> super(tf,SWT.NONE);
>>
>> GridLayout layout = new GridLayout(2,false);
>> setLayout(layout);
>>
>> //Add Scrolled Composite to tabfolder
>> ScrolledComposite sc = new
>> ScrolledComposite(this,SWT.H_SCROLL|SWT.V_SCROLL);
>>
>> //add Group to ScrolledComposite so as to add widgets to it.
>> Group g = new Group(sc,SWT.SHADOW_ETCHED_IN);
>> GridData gridsc = new GridData(GridData.FILL_BOTH);
>> sc.setLayoutData(gridsc);
>> System.out.println(tf.getBackground());
>>
>> Color clr = tf.getBackground();
>> sc.setBackground(clr);
>> System.out.println(sc.getBackground());
>>
>> //always show scroll bars
>> sc.setAlwaysShowScrollBars(true);
>> sc.setExpandHorizontal(true);
>> sc.setExpandVertical(true);
>>
>> //set content to group which will contain widgets
>> sc.setContent(g);
>>
>>
>> for(int i=0;i<28;i++)
>> {
>> GridData gridb = new GridData(GridData.FILL_BOTH);
>>
>> //add 28 combo boxes to group
>> Combo b = new Combo(g,SWT.PUSH);
>> b.setText("Button "+i);
>> b.setLayoutData(gridb);
>> b.setToolTipText("Button");
>>
>> //b.pack();
>> }
>> }
>> }
>>

Thanks for letting me know..As you mentioned i set a GridLayoutData for
"Group" and i am creating a new instance of GridData for every Widget i am
adding..just for Group i forgot..and even now i am not able to add widgets
to the "Group" in the "ScrollableComposite" which is there in "TabItem" of
a "TabFolder" ..

(in my case Buttons)

but not a single Button is getting added!

I can see the "TabFolder" ,the "TabItem" which contains the
"ScrollableComposite" which shows the "Group" but nothing on the "Group"!!

This problem i have faced previously too..If i add by passing "this" as
the argument while creating the "Composite/Control object" it adds itself
to the Composite parent i have passed..but if i explicitly mention the
"Composite parent" in the argument while creating ..it doesn't add itself
..or maybe it adds but doen't show on screen or the Shell created!!

Thanks.
Adding "Widgets" to "ScrolledComposites" in a "TabItem" [message #268043 is a reply to message #267949] Sun, 25 January 2009 08:07 Go to previous messageGo to next message
Eclipse UserFriend
Hi..I want to add
"Buttons",
"Labels",
"Text boxes",
"Combo boxes"

on the "ScrolledComposite" present on the "TabItem" ,


so how do i do it????



I tried putting a "Group" on the "ScrolledComposite" which i did
successfully,

but then couldn't add more "WIDGETS" on it..

Could anyone help??
Re: Adding "Widgets" to "ScrolledComposites" in a "TabItem" [message #268081 is a reply to message #268043] Mon, 26 January 2009 13:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 1/25/2009 8:07 AM, adithya wrote:
> Hi..I want to add "Buttons",
> "Labels",
> "Text boxes",
> "Combo boxes"
> on the "ScrolledComposite" present on the "TabItem" ,
>
>
> so how do i do it????
>
>
>
> I tried putting a "Group" on the "ScrolledComposite" which i did
> successfully,
>
> but then couldn't add more "WIDGETS" on it..
>
> Could anyone help??

Please read the JavaDoc comments for ScrolledComposite; it explains how
to use the class and also gives some example code.
You also need to learn more about Composites and Layouts and other
related topics.

Here is some more example code for you to look at. Make sure you study
to understand what each part is doing and why, otherwise you will
continue to be confused by layout problems.

public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

final TabFolder tabFolder = new TabFolder(shell, SWT.NONE);

final TabItem tab1TabItem = new TabItem(tabFolder, SWT.NONE);
tab1TabItem.setText("Tab1");

final ScrolledComposite scrolledComposite = new
ScrolledComposite(tabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setExpandHorizontal(true);
tab1TabItem.setControl(scrolledComposite);

final Composite composite = new Composite(scrolledComposite, SWT.NONE);
scrolledComposite.setContent(composite);
final GridLayout gridLayout_1 = new GridLayout();
gridLayout_1.numColumns = 3;
composite.setLayout(gridLayout_1);

for (int i = 0; i < 10; i++) {
new Label(composite, SWT.NONE).setText("Label " + i);
new Text(composite, SWT.BORDER).setLayoutData(new GridData(SWT.FILL,
SWT.CENTER, true, false));
new Button(composite, SWT.NONE).setText("Button " + i);
}

scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAU LT,
SWT.DEFAULT));

shell.pack();
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
Re: Adding "Widgets" to "ScrolledComposites" in a "TabItem" [message #268239 is a reply to message #268081] Fri, 30 January 2009 22:14 Go to previous message
Eclipse UserFriend
Eric Rizzo wrote:

> On 1/25/2009 8:07 AM, adithya wrote:
>> Hi..I want to add "Buttons",
>> "Labels",
>> "Text boxes",
>> "Combo boxes"
>> on the "ScrolledComposite" present on the "TabItem" ,
>>
>>
>> so how do i do it????
>>
>>
>>
>> I tried putting a "Group" on the "ScrolledComposite" which i did
>> successfully,
>>
>> but then couldn't add more "WIDGETS" on it..
>>
>> Could anyone help??



> Please read the JavaDoc comments for ScrolledComposite; it explains how
> to use the class and also gives some example code.
> You also need to learn more about Composites and Layouts and other
> related topics.

> Here is some more example code for you to look at. Make sure you study
> to understand what each part is doing and why, otherwise you will
> continue to be confused by layout problems.

> public static void main(String[] args) {
> Display display = new Display();
> final Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());

> final TabFolder tabFolder = new TabFolder(shell, SWT.NONE);

> final TabItem tab1TabItem = new TabItem(tabFolder, SWT.NONE);
> tab1TabItem.setText("Tab1");

> final ScrolledComposite scrolledComposite = new
> ScrolledComposite(tabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
> scrolledComposite.setExpandVertical(true);
> scrolledComposite.setExpandHorizontal(true);
> tab1TabItem.setControl(scrolledComposite);

> final Composite composite = new Composite(scrolledComposite, SWT.NONE);
> scrolledComposite.setContent(composite);
> final GridLayout gridLayout_1 = new GridLayout();
> gridLayout_1.numColumns = 3;
> composite.setLayout(gridLayout_1);

> for (int i = 0; i < 10; i++) {
> new Label(composite, SWT.NONE).setText("Label " + i);
> new Text(composite, SWT.BORDER).setLayoutData(new GridData(SWT.FILL,
> SWT.CENTER, true, false));
> new Button(composite, SWT.NONE).setText("Button " + i);
> }

> scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAU LT,
> SWT.DEFAULT));

> shell.pack();
> shell.open();

> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> display.dispose();
> }


Thanks a lot for clearing my doubts..
Previous Topic:Installing IDE for Java Developers
Next Topic:Question - Indexing versus Perspectives
Goto Forum:
  


Current Time: Sun Jun 01 16:06:52 EDT 2025

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

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

Back to the top