Dynamic set of composites in a ScrolledComposite [message #478712] |
Thu, 06 August 2009 13:52 |
Jordan Bonnet Messages: 15 Registered: July 2009 |
Junior Member |
|
|
Hi All,
I would like to know what the best strategy is to create a set of
composites in a ScrolledComposite, given that this set might be changed
dynamically.
*** My Context ***
Actually what I want to do is something like a ListViewer (jface) but with
a kind of Facebook style : the items populating the Viewer would be a
custom composite instead of being some text. This custom composite has an
image, two lines (labels) and some buttons (for actions!).
*** What I tried ***
In order to achieve this wonderful custom Viewer, I used a
ScrolledComposite and a Composite, using a sample code I found on
java2s.com :
final Composite parent = new Composite(scrollComposite, SWT.NONE);
scrollComposite.setContent(parent);
scrollComposite.setExpandVertical(true);
scrollComposite.setExpandHorizontal(true);
scrollComposite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle r = scrollComposite.getClientArea();
scrollComposite.setMinSize(parent.computeSize(r.width,
SWT.DEFAULT));
}
});
*** Problems ***
I tried to call explicitly dispose() on each item that I wanted to
eliminate during a refresh, but it did not seem to work. And I used the
DisposeListener to propagate the event to the descendants, but still..
Then I decided to cache the Composite items populating my viewer, so that
when refreshing, instead of destroying and recreating I updated the items
with their new values, and hid the extra items (GridData#exclude = true;
setVisible(false)) or created new ones if necessary (I hope it is not too
confusing).
Then I also got an issue with the ScrolledComposite:
if my viewer goes from 25 items (Vertical scroll showing) to 2 items
(Vertical scroll should not be shown), the scroll bar persists and is
still visible.
*** Suggestions ??? ***
Is there any sample of code where I can find something similar to my need?
|
|
|
Re: Dynamic set of composites in a ScrolledComposite [message #478779 is a reply to message #478712] |
Thu, 06 August 2009 19:58 |
Jordan Bonnet Messages: 15 Registered: July 2009 |
Junior Member |
|
|
I am going to reply to myself since I found out the fix!
It is necessary to call layout() on the scrolledcomposite after setting
the minsize! Also i'm using the cached items strategy as I explained in
the previous message(First populate is slow but then it is 5 times
faster!).
Snippet:
final Composite parent = new Composite(scrollComposite, SWT.NONE);
scrollComposite.setContent(parent);
scrollComposite.setExpandVertical(true);
scrollComposite.setExpandHorizontal(true);
scrollComposite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle r = scrollComposite.getClientArea();
scrollComposite.setMinSize(parent.computeSize(r.width,
SWT.DEFAULT));
// FIX : call layout!!
scrollComposite.layout();
}
});
So I guess I don't need any help on this topic anymore!!
Greets!
Jordan Bonnet wrote:
> Hi All,
> I would like to know what the best strategy is to create a set of
> composites in a ScrolledComposite, given that this set might be changed
> dynamically.
> *** My Context ***
> Actually what I want to do is something like a ListViewer (jface) but with
> a kind of Facebook style : the items populating the Viewer would be a
> custom composite instead of being some text. This custom composite has an
> image, two lines (labels) and some buttons (for actions!).
> *** What I tried ***
> In order to achieve this wonderful custom Viewer, I used a
> ScrolledComposite and a Composite, using a sample code I found on
> java2s.com :
> final Composite parent = new Composite(scrollComposite, SWT.NONE);
> scrollComposite.setContent(parent);
> scrollComposite.setExpandVertical(true);
> scrollComposite.setExpandHorizontal(true);
> scrollComposite.addControlListener(new ControlAdapter() {
> public void controlResized(ControlEvent e) {
> Rectangle r = scrollComposite.getClientArea();
> scrollComposite.setMinSize(parent.computeSize(r.width,
> SWT.DEFAULT));
> }
> });
> *** Problems ***
> I tried to call explicitly dispose() on each item that I wanted to
> eliminate during a refresh, but it did not seem to work. And I used the
> DisposeListener to propagate the event to the descendants, but still..
> Then I decided to cache the Composite items populating my viewer, so that
> when refreshing, instead of destroying and recreating I updated the items
> with their new values, and hid the extra items (GridData#exclude = true;
> setVisible(false)) or created new ones if necessary (I hope it is not too
> confusing).
> Then I also got an issue with the ScrolledComposite:
> if my viewer goes from 25 items (Vertical scroll showing) to 2 items
> (Vertical scroll should not be shown), the scroll bar persists and is
> still visible.
> *** Suggestions ??? ***
> Is there any sample of code where I can find something similar to my need?
|
|
|
Powered by
FUDForum. Page generated in 0.02965 seconds