Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to re-layout controls in a view(Problem with re-layouting and refreshing a view)
icon5.gif  How to re-layout controls in a view [message #535092] Fri, 21 May 2010 09:42 Go to next message
Bjoern Berg is currently offline Bjoern BergFriend
Messages: 41
Registered: November 2009
Location: Essen
Member
Hi all,

I don't know if this is the right forum for posting my problem, but I consider it is strongly related to SWT.

I have the following situation:
I created an Eclipse ViewPart with a RowLayout. I use the RowLayout to layout several Canvas on the view. This works like expected and looks like this

Canvas 1 | Canvas 2 | Canvas 3
Canvas 4 | Canvas 5 | Canvas 6

The user is now able to dispose such a Canvas. This works also, but the problem now is, if I dispose Canvas 2 there is free space in the view. What I want is, that I can rearrange the Canvas-objects programatically. The view does it itself if you resize or minimize and maximize it again.

But what do I have to write, that it is automatically done, if the Canvas is disposed?

I tested the following, but it does not work (Widget is my own extension of Canvas):
((Widget)w).dispose();

Widget[] controls = {(Widget)w};
this.parent.changed(controls);
this.parent.layout(true, true);
this.parent.update();

Maybe someone can help or give a hint?

Bjoern
Re: How to re-layout controls in a view [message #535107 is a reply to message #535092] Fri, 21 May 2010 10:13 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
package org.eclipse.swt.snippets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Snippet
{
    static Display display;

    static Shell shell;

    public static void main(String[] args)
    {
        display = new Display();
        shell = new Shell(display);
        shell.setSize(300, 300);
        shell.open();
        shell.setLayout(new GridLayout(5, true));
        int size = 20;
        for (int i = 0; i < size; i++)
        {
            Button button = new Button(shell, SWT.None);
            button.setText("b" + (i + 1));
            button.addSelectionListener(new SelectionAdapter()
            {
                @Override
                public void widgetSelected(SelectionEvent e)
                {
                    e.widget.dispose();
                    // shell.layout();
                }
            });
        }
        shell.layout();
        while (!shell.isDisposed())
        {
            if (!display.readAndDispatch()) display.sleep();
        }
        display.dispose();
    }
}


this snippet reproduces u r problem...

uncommenting shell.layout rearranges as u want....

can u reproduce the issue


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Fri, 21 May 2010 10:14]

Report message to a moderator

icon14.gif  Re: How to re-layout controls in a view [message #535116 is a reply to message #535107] Fri, 21 May 2010 10:52 Go to previous message
Bjoern Berg is currently offline Bjoern BergFriend
Messages: 41
Registered: November 2009
Location: Essen
Member
Vijay,

thank you for the quick response.

Your snippet helped me a lot to analyze the problem. I had a mistake in the definition of the RowLayout. It isn't a good idea to set pack = false.

When I fixed it to

RowLayout layout1 = new RowLayout(SWT.HORIZONTAL);
layout1.pack = true;


everything works fine now.

Bjoern

PS: I know, that I don't have to set pack explicitly to true. But it is easier for the understanding. Very Happy
Previous Topic:Change text to read only
Next Topic:Building Swt 64 bit
Goto Forum:
  


Current Time: Wed Aug 21 14:31:13 GMT 2019

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

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

Back to the top