Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » how to display multi-selectable images
how to display multi-selectable images [message #460664] Fri, 02 September 2005 21:15 Go to next message
Eclipse UserFriend
Originally posted by: kielni.excite.com

I am trying to create something that displays multiple images, and allows
multi-select. It should work something like the View Large Icons mode in
the Windows file explorer, or View as Icons on the Mac Finder; basically a
wrapping list with images.

I tried creating SWT.FLAT buttons and laying them out with a RowLayout;
that looks the way I want, but I can't select multiple buttons at once. I
know TableViewer supports multi-select, but then when I resize the window
I'll have to figure out how many columns will fit and re-populate all of
the cells. Is there an easier way?

Kimberly
Re: how to display multi-selectable images [message #460703 is a reply to message #460664] Sun, 04 September 2005 18:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: murban.javalobby.org

> I tried creating SWT.FLAT buttons and laying them out
> with a RowLayout;
> that looks the way I want, but I can't select
> multiple buttons at once.

I have a possible solution for you. I have not tried it, and I don't work with SWT a lot, but in theory it should work.

Go with the RowLayout like you do above, but attach a MouseEvent listener with a stateMask to each button. If the MouseEvent occurs with the stateMask (Ctrl + Click) for example, add the button to a list (as in a linked list or ArrayList or something. Not an SWT list). Later, when you want to perform whatever action it is you want to perform, just iterate over the list and do it on all of the buttons that have been accumulated in the list. A very simple example (untested code) would be something like this:

/* Qualified name will probably be necessary to avoid
 * name collision with the SWT list.
 */

java.util.List selectList = new LinkedList();

...

button.addMouseListener(new MouseAdapter() {
   public void mouseDown(MouseEvent w) {
      if (e.stateMask == SWT.SHIFT) {
         selectList.add(button);
         // Other stuff like changing border of button
         // to indicate it is selected.
      }
   }
}


Of course, then in the action handler, you simply iterate over the list and perform whatever action you want for each button that has been added to the list. In the mouseDown method, you might also want to make it a toggle by checking to see if it is already in the list, and then removing it if it is or something, and changing the button appearance accordingly. But this should give you a base to build on.

Let me know if it works for you.
Re: how to display multi-selectable images [message #460915 is a reply to message #460703] Fri, 09 September 2005 18:06 Go to previous message
Eclipse UserFriend
Originally posted by: kielni.excite.com

Thanks, that got me on the right track. I gave up on using Buttons
though and drew my image on to a Canvas instead.

Kimberly

Michael Urban wrote:
>>I tried creating SWT.FLAT buttons and laying them out
>>with a RowLayout;
>>that looks the way I want, but I can't select
>>multiple buttons at once.
>
>
> I have a possible solution for you. I have not tried it, and I don't work with SWT a lot, but in theory it should work.
>
> Go with the RowLayout like you do above, but attach a MouseEvent listener with a stateMask to each button. If the MouseEvent occurs with the stateMask (Ctrl + Click) for example, add the button to a list (as in a linked list or ArrayList or something. Not an SWT list). Later, when you want to perform whatever action it is you want to perform, just iterate over the list and do it on all of the buttons that have been accumulated in the list. A very simple example (untested code) would be something like this:
>
>
> /* Qualified name will probably be necessary to avoid
>  * name collision with the SWT list.
>  */
> 
> java.util.List selectList = new LinkedList();
> 
> ..
> 
> button.addMouseListener(new MouseAdapter() {
>    public void mouseDown(MouseEvent w) {
>       if (e.stateMask == SWT.SHIFT) {
>          selectList.add(button);
>          // Other stuff like changing border of button
>          // to indicate it is selected.
>       }
>    }
> }
> 

>
> Of course, then in the action handler, you simply iterate over the list and perform whatever action you want for each button that has been added to the list. In the mouseDown method, you might also want to make it a toggle by checking to see if it is already in the list, and then removing it if it is or something, and changing the button appearance accordingly. But this should give you a base to build on.
>
> Let me know if it works for you.
Previous Topic:ToolBar with Text widget
Next Topic:Solution for wrapping SWT Button Text
Goto Forum:
  


Current Time: Fri Apr 26 19:30:56 GMT 2024

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

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

Back to the top