Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Is there a way to always show the scrollbar for a List?
Is there a way to always show the scrollbar for a List? [message #537264] Tue, 01 June 2010 17:29 Go to next message
Tony is currently offline TonyFriend
Messages: 52
Registered: July 2009
Member
I'm using org.eclipse.swt.widgets.List and I want to always show the
scrollbar (disabled if the list doesn't need to be scrolled, enabled if it
does). Is there a way to do this?

Thanks
Re: Is there a way to always show the scrollbar for a List? [message #537334 is a reply to message #537264] Wed, 02 June 2010 05:30 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
package org.eclipse.swt.snippets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;

public class Snippet
{
    static Display display;

    static Shell shell;

    public static void main(String[] args)
    {
        display = new Display();
        shell = new Shell(display);
        shell.setSize(300, 300);
        shell.open();
        shell.setLayout(new GridLayout(5, true));
        List list = new List(shell, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
        GridData layoutData = new GridData(GridData.FILL_BOTH);
        list.setLayoutData(layoutData);
        list.setItems(new String[] { "1", "2", "3" });

        list.addSelectionListener(new SelectionListener()
        {

            @Override
            public void widgetSelected(SelectionEvent e)
            {
                // TODO Auto-generated method stub

            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e)
            {
                System.out.println();

            }
        });
        shell.layout();
        ScrollBar hBar = list.getHorizontalBar();
        if (hBar != null) hBar.setVisible(true);
        ScrollBar vBar = list.getVerticalBar();
        if (vBar != null) vBar.setVisible(true);

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


pls modify the code further to sute your needs...


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Wed, 02 June 2010 05:33]

Report message to a moderator

Re: Is there a way to always show the scrollbar for a List? [message #537881 is a reply to message #537334] Fri, 04 June 2010 03:13 Go to previous messageGo to next message
Tony is currently offline TonyFriend
Messages: 52
Registered: July 2009
Member
Thank you for your reply. I see that your example does work and that's what
I thought I'd need to do, however something is overriding the value that is
set via the scrollbar visible property. My list is declared within a
org.eclipse.jface.wizard.WizardPage (which is added to an
org.eclipse.jface.wizard.Wizard). Does anyone know how to always show a
list's scrollbars when the list is declared within a JFace WizardPage?
Re: Is there a way to always show the scrollbar for a List? [message #537885 is a reply to message #537881] Fri, 04 June 2010 04:55 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
Notice that the layout is done defore and setting visible is done after...

shell.layout();
        ScrollBar hBar = list.getHorizontalBar();
        if (hBar != null) hBar.setVisible(true);
        ScrollBar vBar = list.getVerticalBar();
        if (vBar != null) vBar.setVisible(true);


if u do it the other way the same thing will happen which is happening to u...


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Is there a way to always show the scrollbar for a List? [message #537938 is a reply to message #537885] Fri, 04 June 2010 08:55 Go to previous message
Tony is currently offline TonyFriend
Messages: 52
Registered: July 2009
Member
Thanks that fixed my issue.
Previous Topic:SWT_AWT compatibility
Next Topic:Wizard page's content does not show in a standalone JFace/SWT application
Goto Forum:
  


Current Time: Tue Apr 16 17:21:38 GMT 2024

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

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

Back to the top