Home » Newcomers » Newcomers » Adding "Vertical ScrollBar" to a "TabFolder"
| | | |
Re: Adding "Vertical ScrollBar" to a "TabFolder" [message #267898 is a reply to message #267857] |
Wed, 21 January 2009 11:19   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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.
|
|
| |
Re: Adding "Widgets" to "ScrolledComposites" in a "TabItem" [message #268081 is a reply to message #268043] |
Mon, 26 January 2009 13:05   |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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..
|
|
|
Goto Forum:
Current Time: Sun Jun 01 16:06:52 EDT 2025
Powered by FUDForum. Page generated in 0.28331 seconds
|