Is it possible to get the vertical/horizontal scroll bar visible when the SWT List is in disabled state?
Asked Answered
L

2

1

I have a list in a composite and is defined in the following way :

List list = new List(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);

when the list is in disabled state (list.setEnabled(false);), and the values inside the list are more than the height of the list, is there any way to make the vertical scroll bar enabled?

Lipscomb answered 17/3, 2014 at 9:16 Comment(0)
S
4

The scroll bars are handled by the OS. Consequently, the OS will decide when to show/hide the scroll bars and when to let the user use them. You can't influence that.

There is a very similar question here.


However, you can wrap your List in a ScrolledComposite. This way, you can still scroll even if the List is disabled:

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

    final ScrolledComposite composite = new ScrolledComposite(shell, SWT.V_SCROLL);
    composite.setLayout(new FillLayout());

    List list = new List(composite, SWT.NONE);

    for (int i = 0; i < 20; i++)
    {
        list.add("Item: " + i);
    }

    composite.setContent(list);
    composite.setExpandHorizontal(true);
    composite.setExpandVertical(true);
    composite.setMinSize(list.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    list.setEnabled(false);

    shell.pack();
    shell.setSize(100, 150);
    shell.open();
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

Looks like this:

enter image description here

Sauls answered 17/3, 2014 at 9:29 Comment(0)
V
0

Context

I had encountred this issue last week i had to enable scrollbars in a disabled table view to prevent users from checking items checkboxes.

Solution

Since we can't enable vertical and horizontal scrollbars in disabled table view, i just prevent user from checking the checkboxes when he is not supposed to, and i also make item on gray foreground when the table is supposed to be disabled.

Vazquez answered 17/11, 2016 at 10:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.