Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to enable scroll in disabled tree
How to enable scroll in disabled tree [message #482625] Thu, 27 August 2009 10:05 Go to next message
Anubhav Manak is currently offline Anubhav ManakFriend
Messages: 17
Registered: July 2009
Junior Member
Hi,

Tree.setEnable(false) also disables scrollbars. How can I enable
scrollbars of disabled tree???
Re: How to enable scroll in disabled tree [message #483500 is a reply to message #482625] Tue, 01 September 2009 18:53 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

This question comes up frequently, so I've created a snippet for it, see
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet322 .java .
Please note its comment though:

"Note that this goes against conventional UI behaviour, where disabling a
control typically disables its scrollbars as well."

The snippet is also pasted below, since it can take a while for new snippets
to replicate on the eclipse.org servers:

public static void main (String[] args) {
final Display display = new Display ();
Shell shell = new Shell (display);
shell.setBounds (10, 10, 300, 300);
final ScrolledComposite sc = new ScrolledComposite (shell,
SWT.VERTICAL);
sc.setBounds (10, 10, 280, 200);
final int clientWidth = sc.getClientArea ().width;

final Tree tree = new Tree (sc, SWT.NONE);
for (int i = 0; i < 99; i++) {
TreeItem item = new TreeItem (tree, SWT.NONE);
item.setText ("item " + i);
new TreeItem (item, SWT.NONE).setText ("child");
}
sc.setContent (tree);
int prefHeight = tree.computeSize (SWT.DEFAULT, SWT.DEFAULT).y;
tree.setSize (clientWidth, prefHeight);
/*
* The following listener ensures that the Tree is always large
* enough to not need to show its own vertical scrollbar.
*/
tree.addTreeListener (new TreeListener () {
public void treeExpanded (TreeEvent e) {
int prefHeight = tree.computeSize (SWT.DEFAULT, SWT.DEFAULT).y;
tree.setSize (clientWidth, prefHeight);
}
public void treeCollapsed (TreeEvent e) {
int prefHeight = tree.computeSize (SWT.DEFAULT, SWT.DEFAULT).y;
tree.setSize (clientWidth, prefHeight);
}
});
/*
* The following listener ensures that a newly-selected item
* in the Tree is always visible.
*/
tree.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
TreeItem [] selectedItems = tree.getSelection();
if (selectedItems.length > 0) {
Rectangle itemRect = selectedItems[0].getBounds();
Rectangle area = sc.getClientArea();
Point origin = sc.getOrigin();
if (itemRect.x < origin.x || itemRect.y < origin.y
|| itemRect.x + itemRect.width > origin.x + area.width
|| itemRect.y + itemRect.height > origin.y +
area.height) {
sc.setOrigin(itemRect.x, itemRect.y);
}
}
}
});
/*
* The following listener scrolls the Tree one item at a time
* in response to MouseWheel events.
*/
tree.addListener(SWT.MouseWheel, new Listener() {
public void handleEvent(Event event) {
Point origin = sc.getOrigin();
if (event.count < 0) {
origin.y = Math.min(origin.y + tree.getItemHeight(),
tree.getSize().y);
} else {
origin.y = Math.max(origin.y - tree.getItemHeight(), 0);
}
sc.setOrigin(origin);
}
});

Button disableButton = new Button (shell, SWT.PUSH);
disableButton.setBounds (10, 220, 120, 30);
disableButton.setText ("Disable");
disableButton.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event event) {
tree.setEnabled(false);
}
});
Button enableButton = new Button (shell, SWT.PUSH);
enableButton.setBounds (140, 220, 120, 30);
enableButton.setText ("Enable");
enableButton.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event event) {
tree.setEnabled(true);
}
});

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

HTH,
Grant


"Anubhav Manak" <a_manak@yahoo.com> wrote in message
news:12438f0f955a1e2b12e02091a5454e85$1@www.eclipse.org...
> Hi,
>
> Tree.setEnable(false) also disables scrollbars. How can I enable
> scrollbars of disabled tree???
>
Previous Topic:Newbie question: background services/shared objects
Next Topic:RCP product with automatic updates?
Goto Forum:
  


Current Time: Thu Jan 16 20:08:49 GMT 2025

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

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

Back to the top