Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Guidance needed in creating a dynamic GUI environment.
Guidance needed in creating a dynamic GUI environment. [message #445420] Fri, 05 November 2004 12:16 Go to next message
Eclipse UserFriend
Originally posted by: wayneg.ananzi.co.za

Hi all

I've written a whole app using SWT but I'm getting some strange results
that I cannot explain. Most of my problems come about when using dynamic
GUI manipulation. Below I've got a simple example that shows a button that
creates a text box. Firstly the shell starts off smaller that I set it.
When I press the button a text box appears but its under the button. Upon
changing the size manually the layout works right and then when the button
is pressed agian it gets stuffed up again. I have this in a few sections
of my app where dynamicaly creating widgets changes the surrounding
containers size, only to recorrect its self upon manual resize. Am I
missing something?

Thanks
Wayne


<code>
public class Demo {

private static Display display;
private static Shell shell;
private static Canvas canvas,picCan;


public static void main(String[] args) {

FormData data;

display = new Display();

FillLayout fl = new FillLayout();

shell = new Shell(display);

shell.setLocation(40,40);
shell.setSize(600,400);
shell.setLayout(fl);
shell.open();


final Canvas tmpCan = new Canvas(shell, SWT.BORDER);

FormLayout formLayout = new FormLayout();
tmpCan.setLayout(formLayout);

Button but1 = new Button(tmpCan,SWT.PUSH);
data = new FormData();
data.top = new FormAttachment(0);
data.left = new FormAttachment(0,5);
but1.setLayoutData(data);

but1.setText("Test...");
but1.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent me)
{
if(me.button == 1)
{
Text txt = new Text(tmpCan,SWT.SIMPLE);
FormData data = new FormData();
data.top = new FormAttachment(0);
data.left = new FormAttachment(50);
txt.setLayoutData(data);
txt.setText("Added");
tmpCan.pack();

}
}
});
tmpCan.pack();

shell.pack();

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

display.dispose ();
}
}
</code>
Re: Guidance needed in creating a dynamic GUI environment. [message #445438 is a reply to message #445420] Fri, 05 November 2004 16:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Kevin.clark.accessbc.com.nospam

Try using layout() after drawing your new widget.

i.e.

tmpCan.layout();


I'm not sure if I understand exactly what is happening in your situation,
so this is just something to try.

Thanks,
Kevin


Wayne Gemmell wrote:

> Hi all

> I've written a whole app using SWT but I'm getting some strange results
> that I cannot explain. Most of my problems come about when using dynamic
> GUI manipulation. Below I've got a simple example that shows a button that
> creates a text box. Firstly the shell starts off smaller that I set it.
> When I press the button a text box appears but its under the button. Upon
> changing the size manually the layout works right and then when the button
> is pressed agian it gets stuffed up again. I have this in a few sections
> of my app where dynamicaly creating widgets changes the surrounding
> containers size, only to recorrect its self upon manual resize. Am I
> missing something?

> Thanks
> Wayne


> <code>
> public class Demo {

> private static Display display;
> private static Shell shell;
> private static Canvas canvas,picCan;


> public static void main(String[] args) {

> FormData data;

> display = new Display();

> FillLayout fl = new FillLayout();

> shell = new Shell(display);

> shell.setLocation(40,40);
> shell.setSize(600,400);
> shell.setLayout(fl);
> shell.open();


> final Canvas tmpCan = new Canvas(shell, SWT.BORDER);

> FormLayout formLayout = new FormLayout();
> tmpCan.setLayout(formLayout);

> Button but1 = new Button(tmpCan,SWT.PUSH);
> data = new FormData();
> data.top = new FormAttachment(0);
> data.left = new FormAttachment(0,5);
> but1.setLayoutData(data);

> but1.setText("Test...");
> but1.addMouseListener(new MouseAdapter()
> {
> public void mouseDown(MouseEvent me)
> {
> if(me.button == 1)
> {
> Text txt = new Text(tmpCan,SWT.SIMPLE);
> FormData data = new FormData();
> data.top = new FormAttachment(0);
> data.left = new FormAttachment(50);
> txt.setLayoutData(data);
> txt.setText("Added");
> tmpCan.pack();

> }
> }
> });
> tmpCan.pack();

> shell.pack();

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

> display.dispose ();
> }
> }
> </code>
Re: Guidance needed in creating a dynamic GUI environment. [message #445439 is a reply to message #445420] Fri, 05 November 2004 17:54 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
I have fixed your code. The thing that you are missing is that pack()
resizes the composite to it's preferred size as well as laying out the
contents. I think you just want to layout and not resize the composite. If
you actually want the composite to change, what is a happening is that
pack() is resizing it to be small and then when you resize the shell, the
FillLayout is resizing it to be bigger again so it jumps when you resize the
shell. Hope this helps.

import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;

public class Demo {
private static Display display;
private static Shell shell;
private static Canvas canvas, picCan;

public static void main(String[] args) {
FormData data;
display = new Display();
FillLayout fl = new FillLayout();
shell = new Shell(display);
shell.setLocation(40, 40);
shell.setSize(600, 400);
shell.setLayout(fl);
shell.open();

final Canvas tmpCan = new Canvas(shell, SWT.BORDER);

FormLayout formLayout = new FormLayout();
tmpCan.setLayout(formLayout);

Button but1 = new Button(tmpCan, SWT.PUSH);
data = new FormData();
data.top = new FormAttachment(0);
data.left = new FormAttachment(0, 5);
but1.setLayoutData(data);

but1.setText("Test...");
but1.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent me) {
if (me.button == 1) {
Text txt = new Text(tmpCan, SWT.SIMPLE);
FormData data = new FormData();
data.top = new FormAttachment(0);
data.left = new FormAttachment(50);
txt.setLayoutData(data);
txt.setText("Added");
tmpCan.layout();
}
}
});
shell.pack();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

"Wayne Gemmell" <wayneg@ananzi.co.za> wrote in message
news:cmfquc$l6g$1@eclipse.org...
> Hi all
>
> I've written a whole app using SWT but I'm getting some strange results
> that I cannot explain. Most of my problems come about when using dynamic
> GUI manipulation. Below I've got a simple example that shows a button that
> creates a text box. Firstly the shell starts off smaller that I set it.
> When I press the button a text box appears but its under the button. Upon
> changing the size manually the layout works right and then when the button
> is pressed agian it gets stuffed up again. I have this in a few sections
> of my app where dynamicaly creating widgets changes the surrounding
> containers size, only to recorrect its self upon manual resize. Am I
> missing something?
>
> Thanks
> Wayne
>
>
> <code>
> public class Demo {
>
> private static Display display;
> private static Shell shell;
> private static Canvas canvas,picCan;
>
>
> public static void main(String[] args) {
>
> FormData data;
>
> display = new Display();
>
> FillLayout fl = new FillLayout();
>
> shell = new Shell(display);
>
> shell.setLocation(40,40);
> shell.setSize(600,400);
> shell.setLayout(fl);
> shell.open();
>
>
> final Canvas tmpCan = new Canvas(shell, SWT.BORDER);
>
> FormLayout formLayout = new FormLayout();
> tmpCan.setLayout(formLayout);
>
> Button but1 = new Button(tmpCan,SWT.PUSH);
> data = new FormData();
> data.top = new FormAttachment(0);
> data.left = new FormAttachment(0,5);
> but1.setLayoutData(data);
>
> but1.setText("Test...");
> but1.addMouseListener(new MouseAdapter()
> {
> public void mouseDown(MouseEvent me)
> {
> if(me.button == 1)
> {
> Text txt = new Text(tmpCan,SWT.SIMPLE);
> FormData data = new FormData();
> data.top = new FormAttachment(0);
> data.left = new FormAttachment(50);
> txt.setLayoutData(data);
> txt.setText("Added");
> tmpCan.pack();
>
> }
> }
> });
> tmpCan.pack();
>
> shell.pack();
>
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ())
> display.sleep ();
> }
>
> display.dispose ();
> }
> }
> </code>
>
Re: Guidance needed in creating a dynamic GUI environment. [message #445486 is a reply to message #445439] Sun, 07 November 2004 15:41 Go to previous message
Eclipse UserFriend
Originally posted by: wayneg.ananzi.co.za

> tmpCan.layout();
> }
> }
> });
> shell.layout();//I did this.

Thanks, that did the job... I guess I missed that in the docs. I have two
more questions though.

1) In the example how would I remove the textbox specificaly, not empty
everything (I can do that (snippet98)).

2) How do you reset a canvas to its original state? I don't want to
recreate it.
Previous Topic:Best practive with SWT
Next Topic:Sorted Insert into Tree and transparent Labels.
Goto Forum:
  


Current Time: Sat Oct 24 07:15:47 GMT 2020

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

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

Back to the top