Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Scrollable Composite for Icons / thumbnails
Scrollable Composite for Icons / thumbnails [message #446738] Thu, 02 December 2004 03:11 Go to next message
Mani Ghamari is currently offline Mani GhamariFriend
Messages: 33
Registered: July 2009
Member
Hi all,

Im developing a photo gallery application (SWT / stand alone).
Is there a way of implementing a scrollable composite that contains fixed
sized children (icons / thumbnails).

The children should be layed out in a row/wrap manner just like your usual
file explorer (vertical scrolling only. children are put on the next row
upon reaching the right edge of the composite)

My initial attempt was to use a SrollableComposite and put another composite
with RowLayout. Yet, the RowLayout does not automatically rxpand the
composite, when there is no space available at the bottom. and the lenght of
the vertical scrollbar does not represent the size of the underlying
composite.

I'd be greatful for any ideas

Thanks

Mani
Re: Scrollable Composite for Icons / thumbnails [message #446755 is a reply to message #446738] Thu, 02 December 2004 13:48 Go to previous messageGo to next message
Stefan Pietsch is currently offline Stefan PietschFriend
Messages: 68
Registered: July 2009
Member
Hi Mani,

I solved the problem a few days ago. The trick is to manipulate the method
computeSize of the ScrolledComposite and call the method setMinSize if the
size of the application chanded.

See the code below

Bye Stefan

import org.eclipse.swt.SWT;

import org.eclipse.swt.custom.ScrolledComposite;

import org.eclipse.swt.events.ControlAdapter;

import org.eclipse.swt.events.ControlEvent;

import org.eclipse.swt.graphics.Point;

import org.eclipse.swt.graphics.Rectangle;

import org.eclipse.swt.layout.FillLayout;

import org.eclipse.swt.layout.RowLayout;

import org.eclipse.swt.widgets.Button;

import org.eclipse.swt.widgets.Composite;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Shell;

public class ThumbnailTest {

private static ScrolledComposite scrollComposite;

private static Composite thumbsComposite;


public static void main(String[] args) {

Display display = new Display();

Shell shell = new Shell(display);

shell.setLayout(new FillLayout());

shell.setText("ThumbnailTest");

scrollComposite = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.BORDER);

scrollComposite.setLayout(new FillLayout());

scrollComposite.setExpandVertical(true);

scrollComposite.setExpandHorizontal(true);

scrollComposite.addControlListener(new ControlAdapter() {

public void controlResized(ControlEvent e) {

setSize();

}

});

RowLayout layout = new RowLayout(SWT.HORIZONTAL);

layout.wrap = true;

thumbsComposite = new Composite(scrollComposite, SWT.NONE){

public Point computeSize(int wHint, int hHint, boolean changed) {

Rectangle r = getParent().getClientArea();

System.out.println("R="+r.x+"x"+r.y+" "+r.width+"x"+r.height);

return super.computeSize(r.width, SWT.DEFAULT, changed);

}

};

thumbsComposite.setLayout(layout);

scrollComposite.setContent(thumbsComposite);


for(int i = 1; i <= 50; i++) {

// use setImage for Thumbnails

new Button(thumbsComposite, SWT.NONE).setText("Test");

}


shell.open();

while (!shell.isDisposed()) {

if (!display.readAndDispatch()) {

display.sleep();

}

}

display.dispose();

}

private static void setSize() {

scrollComposite.setMinSize(thumbsComposite.computeSize(SWT.D EFAULT,
SWT.DEFAULT));

}

}



"Mani Ghamari" <mani.ghamari@linkast.com> schrieb im Newsbeitrag
news:com15d$ot6$1@www.eclipse.org...

> Hi all,
>
> Im developing a photo gallery application (SWT / stand alone).
> Is there a way of implementing a scrollable composite that contains fixed
> sized children (icons / thumbnails).
>
> The children should be layed out in a row/wrap manner just like your usual
> file explorer (vertical scrolling only. children are put on the next row
> upon reaching the right edge of the composite)
>
> My initial attempt was to use a SrollableComposite and put another
composite
> with RowLayout. Yet, the RowLayout does not automatically rxpand the
> composite, when there is no space available at the bottom. and the lenght
of
> the vertical scrollbar does not represent the size of the underlying
> composite.
>
> I'd be greatful for any ideas
>
> Thanks
>
> Mani
>
>
Re: Scrollable Composite for Icons / thumbnails [message #446758 is a reply to message #446755] Thu, 02 December 2004 14:05 Go to previous messageGo to next message
Mani Ghamari is currently offline Mani GhamariFriend
Messages: 33
Registered: July 2009
Member
Thanks Stefan!

It works perfectly. I really appreciate your help...

Mani


"Stefan Pietsch" <pietsch@multichart.de> wrote in message
news:con6fe$4uv$1@www.eclipse.org...
> Hi Mani,
>
> I solved the problem a few days ago. The trick is to manipulate the method
> computeSize of the ScrolledComposite and call the method setMinSize if the
> size of the application chanded.
>
> See the code below
>
> Bye Stefan
>
> import org.eclipse.swt.SWT;
>
> import org.eclipse.swt.custom.ScrolledComposite;
>
> import org.eclipse.swt.events.ControlAdapter;
>
> import org.eclipse.swt.events.ControlEvent;
>
> import org.eclipse.swt.graphics.Point;
>
> import org.eclipse.swt.graphics.Rectangle;
>
> import org.eclipse.swt.layout.FillLayout;
>
> import org.eclipse.swt.layout.RowLayout;
>
> import org.eclipse.swt.widgets.Button;
>
> import org.eclipse.swt.widgets.Composite;
>
> import org.eclipse.swt.widgets.Display;
>
> import org.eclipse.swt.widgets.Shell;
>
> public class ThumbnailTest {
>
> private static ScrolledComposite scrollComposite;
>
> private static Composite thumbsComposite;
>
>
> public static void main(String[] args) {
>
> Display display = new Display();
>
> Shell shell = new Shell(display);
>
> shell.setLayout(new FillLayout());
>
> shell.setText("ThumbnailTest");
>
> scrollComposite = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.BORDER);
>
> scrollComposite.setLayout(new FillLayout());
>
> scrollComposite.setExpandVertical(true);
>
> scrollComposite.setExpandHorizontal(true);
>
> scrollComposite.addControlListener(new ControlAdapter() {
>
> public void controlResized(ControlEvent e) {
>
> setSize();
>
> }
>
> });
>
> RowLayout layout = new RowLayout(SWT.HORIZONTAL);
>
> layout.wrap = true;
>
> thumbsComposite = new Composite(scrollComposite, SWT.NONE){
>
> public Point computeSize(int wHint, int hHint, boolean changed) {
>
> Rectangle r = getParent().getClientArea();
>
> System.out.println("R="+r.x+"x"+r.y+" "+r.width+"x"+r.height);
>
> return super.computeSize(r.width, SWT.DEFAULT, changed);
>
> }
>
> };
>
> thumbsComposite.setLayout(layout);
>
> scrollComposite.setContent(thumbsComposite);
>
>
> for(int i = 1; i <= 50; i++) {
>
> // use setImage for Thumbnails
>
> new Button(thumbsComposite, SWT.NONE).setText("Test");
>
> }
>
>
> shell.open();
>
> while (!shell.isDisposed()) {
>
> if (!display.readAndDispatch()) {
>
> display.sleep();
>
> }
>
> }
>
> display.dispose();
>
> }
>
> private static void setSize() {
>
> scrollComposite.setMinSize(thumbsComposite.computeSize(SWT.D EFAULT,
> SWT.DEFAULT));
>
> }
>
> }
>
>
>
> "Mani Ghamari" <mani.ghamari@linkast.com> schrieb im Newsbeitrag
> news:com15d$ot6$1@www.eclipse.org...
>
>> Hi all,
>>
>> Im developing a photo gallery application (SWT / stand alone).
>> Is there a way of implementing a scrollable composite that contains fixed
>> sized children (icons / thumbnails).
>>
>> The children should be layed out in a row/wrap manner just like your
>> usual
>> file explorer (vertical scrolling only. children are put on the next row
>> upon reaching the right edge of the composite)
>>
>> My initial attempt was to use a SrollableComposite and put another
> composite
>> with RowLayout. Yet, the RowLayout does not automatically rxpand the
>> composite, when there is no space available at the bottom. and the lenght
> of
>> the vertical scrollbar does not represent the size of the underlying
>> composite.
>>
>> I'd be greatful for any ideas
>>
>> Thanks
>>
>> Mani
>>
>>
>
>
Re: Scrollable Composite for Icons / thumbnails [message #446799 is a reply to message #446755] Thu, 02 December 2004 14:06 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Stefan has the right idea but you do not actually need to subclass Composite
and override computeSize. Here is a simplified version that does the same
thing.

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

final ScrolledComposite scrollComposite = new
ScrolledComposite(shell, SWT.V_SCROLL | SWT.BORDER);
scrollComposite.setExpandVertical(true);
scrollComposite.setExpandHorizontal(true);

final Composite thumbsComposite = new Composite(scrollComposite,
SWT.NONE);
for(int i = 1; i <= 50; i++) {
// use setImage for Thumbnails -- could use Label here
instead
new Button(thumbsComposite, SWT.NONE).setText("Test");
}
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
layout.wrap = true;
thumbsComposite.setLayout(layout);

scrollComposite.setContent(thumbsComposite);
scrollComposite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle r = scrollComposite.getClientArea();
scrollComposite.setMinSize(thumbsComposite.computeSize(r.wid th,
SWT.DEFAULT));
}
});

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


"Stefan Pietsch" <pietsch@multichart.de> wrote in message
news:con6fe$4uv$1@www.eclipse.org...
> Hi Mani,
>
> I solved the problem a few days ago. The trick is to manipulate the method
> computeSize of the ScrolledComposite and call the method setMinSize if the
> size of the application chanded.
>
> See the code below
>
> Bye Stefan
>
> import org.eclipse.swt.SWT;
>
> import org.eclipse.swt.custom.ScrolledComposite;
>
> import org.eclipse.swt.events.ControlAdapter;
>
> import org.eclipse.swt.events.ControlEvent;
>
> import org.eclipse.swt.graphics.Point;
>
> import org.eclipse.swt.graphics.Rectangle;
>
> import org.eclipse.swt.layout.FillLayout;
>
> import org.eclipse.swt.layout.RowLayout;
>
> import org.eclipse.swt.widgets.Button;
>
> import org.eclipse.swt.widgets.Composite;
>
> import org.eclipse.swt.widgets.Display;
>
> import org.eclipse.swt.widgets.Shell;
>
> public class ThumbnailTest {
>
> private static ScrolledComposite scrollComposite;
>
> private static Composite thumbsComposite;
>
>
> public static void main(String[] args) {
>
> Display display = new Display();
>
> Shell shell = new Shell(display);
>
> shell.setLayout(new FillLayout());
>
> shell.setText("ThumbnailTest");
>
> scrollComposite = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.BORDER);
>
> scrollComposite.setLayout(new FillLayout());
>
> scrollComposite.setExpandVertical(true);
>
> scrollComposite.setExpandHorizontal(true);
>
> scrollComposite.addControlListener(new ControlAdapter() {
>
> public void controlResized(ControlEvent e) {
>
> setSize();
>
> }
>
> });
>
> RowLayout layout = new RowLayout(SWT.HORIZONTAL);
>
> layout.wrap = true;
>
> thumbsComposite = new Composite(scrollComposite, SWT.NONE){
>
> public Point computeSize(int wHint, int hHint, boolean changed) {
>
> Rectangle r = getParent().getClientArea();
>
> System.out.println("R="+r.x+"x"+r.y+" "+r.width+"x"+r.height);
>
> return super.computeSize(r.width, SWT.DEFAULT, changed);
>
> }
>
> };
>
> thumbsComposite.setLayout(layout);
>
> scrollComposite.setContent(thumbsComposite);
>
>
> for(int i = 1; i <= 50; i++) {
>
> // use setImage for Thumbnails
>
> new Button(thumbsComposite, SWT.NONE).setText("Test");
>
> }
>
>
> shell.open();
>
> while (!shell.isDisposed()) {
>
> if (!display.readAndDispatch()) {
>
> display.sleep();
>
> }
>
> }
>
> display.dispose();
>
> }
>
> private static void setSize() {
>
> scrollComposite.setMinSize(thumbsComposite.computeSize(SWT.D EFAULT,
> SWT.DEFAULT));
>
> }
>
> }
>
>
>
> "Mani Ghamari" <mani.ghamari@linkast.com> schrieb im Newsbeitrag
> news:com15d$ot6$1@www.eclipse.org...
>
>> Hi all,
>>
>> Im developing a photo gallery application (SWT / stand alone).
>> Is there a way of implementing a scrollable composite that contains fixed
>> sized children (icons / thumbnails).
>>
>> The children should be layed out in a row/wrap manner just like your
>> usual
>> file explorer (vertical scrolling only. children are put on the next row
>> upon reaching the right edge of the composite)
>>
>> My initial attempt was to use a SrollableComposite and put another
> composite
>> with RowLayout. Yet, the RowLayout does not automatically rxpand the
>> composite, when there is no space available at the bottom. and the lenght
> of
>> the vertical scrollbar does not represent the size of the underlying
>> composite.
>>
>> I'd be greatful for any ideas
>>
>> Thanks
>>
>> Mani
>>
>>
>
>
Re: Scrollable Composite for Icons / thumbnails [message #446800 is a reply to message #446799] Thu, 02 December 2004 14:44 Go to previous message
Stefan Pietsch is currently offline Stefan PietschFriend
Messages: 68
Registered: July 2009
Member
Hi Veronika,

thanks for the idea. I changed my code too.

Bye Stefan

"Veronika Irvine" <veronika_irvine@oti.com> schrieb im Newsbeitrag
news:con7hv$7s5$1@www.eclipse.org...
> Stefan has the right idea but you do not actually need to subclass
Composite
> and override computeSize. Here is a simplified version that does the same
> thing.
>
> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> shell.setText("ThumbnailTest");
>
> final ScrolledComposite scrollComposite = new
> ScrolledComposite(shell, SWT.V_SCROLL | SWT.BORDER);
> scrollComposite.setExpandVertical(true);
> scrollComposite.setExpandHorizontal(true);
>
> final Composite thumbsComposite = new Composite(scrollComposite,
> SWT.NONE);
> for(int i = 1; i <= 50; i++) {
> // use setImage for Thumbnails -- could use Label here
> instead
> new Button(thumbsComposite, SWT.NONE).setText("Test");
> }
> RowLayout layout = new RowLayout(SWT.HORIZONTAL);
> layout.wrap = true;
> thumbsComposite.setLayout(layout);
>
> scrollComposite.setContent(thumbsComposite);
> scrollComposite.addControlListener(new ControlAdapter() {
> public void controlResized(ControlEvent e) {
> Rectangle r = scrollComposite.getClientArea();
>
scrollComposite.setMinSize(thumbsComposite.computeSize(r.wid th,
> SWT.DEFAULT));
> }
> });
>
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> display.dispose();
> }
>
>
> "Stefan Pietsch" <pietsch@multichart.de> wrote in message
> news:con6fe$4uv$1@www.eclipse.org...
> > Hi Mani,
> >
> > I solved the problem a few days ago. The trick is to manipulate the
method
> > computeSize of the ScrolledComposite and call the method setMinSize if
the
> > size of the application chanded.
> >
> > See the code below
> >
> > Bye Stefan
> >
> > import org.eclipse.swt.SWT;
> >
> > import org.eclipse.swt.custom.ScrolledComposite;
> >
> > import org.eclipse.swt.events.ControlAdapter;
> >
> > import org.eclipse.swt.events.ControlEvent;
> >
> > import org.eclipse.swt.graphics.Point;
> >
> > import org.eclipse.swt.graphics.Rectangle;
> >
> > import org.eclipse.swt.layout.FillLayout;
> >
> > import org.eclipse.swt.layout.RowLayout;
> >
> > import org.eclipse.swt.widgets.Button;
> >
> > import org.eclipse.swt.widgets.Composite;
> >
> > import org.eclipse.swt.widgets.Display;
> >
> > import org.eclipse.swt.widgets.Shell;
> >
> > public class ThumbnailTest {
> >
> > private static ScrolledComposite scrollComposite;
> >
> > private static Composite thumbsComposite;
> >
> >
> > public static void main(String[] args) {
> >
> > Display display = new Display();
> >
> > Shell shell = new Shell(display);
> >
> > shell.setLayout(new FillLayout());
> >
> > shell.setText("ThumbnailTest");
> >
> > scrollComposite = new ScrolledComposite(shell, SWT.V_SCROLL |
SWT.BORDER);
> >
> > scrollComposite.setLayout(new FillLayout());
> >
> > scrollComposite.setExpandVertical(true);
> >
> > scrollComposite.setExpandHorizontal(true);
> >
> > scrollComposite.addControlListener(new ControlAdapter() {
> >
> > public void controlResized(ControlEvent e) {
> >
> > setSize();
> >
> > }
> >
> > });
> >
> > RowLayout layout = new RowLayout(SWT.HORIZONTAL);
> >
> > layout.wrap = true;
> >
> > thumbsComposite = new Composite(scrollComposite, SWT.NONE){
> >
> > public Point computeSize(int wHint, int hHint, boolean changed) {
> >
> > Rectangle r = getParent().getClientArea();
> >
> > System.out.println("R="+r.x+"x"+r.y+" "+r.width+"x"+r.height);
> >
> > return super.computeSize(r.width, SWT.DEFAULT, changed);
> >
> > }
> >
> > };
> >
> > thumbsComposite.setLayout(layout);
> >
> > scrollComposite.setContent(thumbsComposite);
> >
> >
> > for(int i = 1; i <= 50; i++) {
> >
> > // use setImage for Thumbnails
> >
> > new Button(thumbsComposite, SWT.NONE).setText("Test");
> >
> > }
> >
> >
> > shell.open();
> >
> > while (!shell.isDisposed()) {
> >
> > if (!display.readAndDispatch()) {
> >
> > display.sleep();
> >
> > }
> >
> > }
> >
> > display.dispose();
> >
> > }
> >
> > private static void setSize() {
> >
> > scrollComposite.setMinSize(thumbsComposite.computeSize(SWT.D EFAULT,
> > SWT.DEFAULT));
> >
> > }
> >
> > }
> >
> >
> >
> > "Mani Ghamari" <mani.ghamari@linkast.com> schrieb im Newsbeitrag
> > news:com15d$ot6$1@www.eclipse.org...
> >
> >> Hi all,
> >>
> >> Im developing a photo gallery application (SWT / stand alone).
> >> Is there a way of implementing a scrollable composite that contains
fixed
> >> sized children (icons / thumbnails).
> >>
> >> The children should be layed out in a row/wrap manner just like your
> >> usual
> >> file explorer (vertical scrolling only. children are put on the next
row
> >> upon reaching the right edge of the composite)
> >>
> >> My initial attempt was to use a SrollableComposite and put another
> > composite
> >> with RowLayout. Yet, the RowLayout does not automatically rxpand the
> >> composite, when there is no space available at the bottom. and the
lenght
> > of
> >> the vertical scrollbar does not represent the size of the underlying
> >> composite.
> >>
> >> I'd be greatful for any ideas
> >>
> >> Thanks
> >>
> >> Mani
> >>
> >>
> >
> >
>
>
Previous Topic:[TreeViewer] Force update
Next Topic:Safari Browser
Goto Forum:
  


Current Time: Thu Apr 25 21:21:33 GMT 2024

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

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

Back to the top