Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Adding Scrollbars to a Window(Scrollbars aren't created)
Adding Scrollbars to a Window [message #686565] Wed, 22 June 2011 14:01 Go to next message
ouri.maler is currently offline ouri.malerFriend
Messages: 22
Registered: July 2010
Junior Member
I'm working on a GUI that consists of a multi-tabbed window, with each tab having its Buttons, Text consoles and the such.
Now, under certain circumstances, the window is going to be too large to fit into the screen. Because of that, I wanted to make it so that one could scroll horizontally and vertically through it (something I had no problem doing earlier with the Text consoles).
As it stands, the relevant code goes like this:
public void init(){
    ...
    final Shell shell = new Shell(display);
    ...
    final TabFolder tabFolder = new TabFolder (shell, SWT.V_SCROLL | SWT.H_SCROL);
    TabItem controls = new TabItem (tabFolder, SWT.NONE);
    TabItem graphView = new TabItem (tabFolder, SWT.NONE);
    TabItem refinement = new TabItem (tabFolder, SWT.NONE);
    ...
    Composite composite = new Composite(tabFolder, SWT.NONE);
    composite.setLayout(lineLayout);
    controls.setControl(composite);
    Composite buttons = new Composite(composite, SWT.NONE);
    mainConsole = new Text(composite, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    ....


No matter how much I resize, though, the shell window still doesn't have any scrollbars (though the mainConsole Text within it does). What mistake am I making here?
Re: Adding Scrollbars to a Window [message #687776 is a reply to message #686565] Thu, 23 June 2011 07:56 Go to previous messageGo to next message
Lakshmi P ShanmugamFriend
Messages: 279
Registered: July 2009
Location: India
Senior Member
Hi,

You can create a ScrolledComposite inside the shell and the TabFolder inside the ScrolledComposite. The ScrolledComposite will manage the scrollbars and show them when required.
For eg:
final Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
ScrolledComposite composite = new ScrolledComposite(shell,SWT.H_SCROLL |SWT.V_SCROLL);
...
final TabFolder tabFolder = new TabFolder (composite, SWT.BORDER);
...

See example snippets on how to use ScrolledComposite here --> http://eclipse.org/swt/snippets/#scrolledcomposite


Lakshmi P Shanmugam
Re: Adding Scrollbars to a Window [message #687938 is a reply to message #687776] Thu, 23 June 2011 14:51 Go to previous messageGo to next message
ouri.maler is currently offline ouri.malerFriend
Messages: 22
Registered: July 2010
Junior Member
Following your advice, I tried the following approach:

public void init(){
    ...
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    ...
    final ScrolledComposite scrolledComposite = new ScrolledComposite(shell, SWT.H_SCROLL |SWT.V_SCROLL);
    scrolledComposite.setLayout(new FillLayout());
    final TabFolder tabFolder = new TabFolder (scrolledComposite, SWT.BORDER);
    TabItem controls = new TabItem (tabFolder, SWT.NONE);
    TabItem graphView = new TabItem (tabFolder, SWT.NONE);
    TabItem refinement = new TabItem (tabFolder, SWT.NONE);
    ...
    Composite composite = new Composite(tabFolder, SWT.NONE);
    composite.setLayout(lineLayout);
    controls.setControl(composite);
    Composite buttons = new Composite(composite, SWT.NONE);
    mainConsole = new Text(composite, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    ....


Unfortunately, this only seems to aggravate the situation - not only do scrollbars still not appear, but now the window is also very small when I launch the program (though it can be resized manually).
I've looked at the snippets and tried a few variations (such as declaring or not declaring a Layout for the ScrolledComposite), but I can't seem to find the cause...
Re: Adding Scrollbars to a Window [message #688348 is a reply to message #687938] Fri, 24 June 2011 13:44 Go to previous message
ouri.maler is currently offline ouri.malerFriend
Messages: 22
Registered: July 2010
Junior Member
Found the solution - the trick was adding the following line:

scrolledComposite.setContent(tabFolder);
Previous Topic:Problem with ImageData and Relative Path
Next Topic:enabling WebGL support in browser widget
Goto Forum:
  


Current Time: Fri Apr 19 19:15:58 GMT 2024

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

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

Back to the top