Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Layout problem when resizing shell
Layout problem when resizing shell [message #721320] Thu, 01 September 2011 13:12 Go to next message
christian.packenius is currently offline christian.packenius
Messages: 2
Registered: September 2011
Junior Member
Hello,

I have a very complex GUI in a program but there's a bug in it. I broke it done to a little snippet to show you (hoping, you can help me).

In this snippet I have a multi line text widget at the bottom and anything (here: a button) above. You can see my problem when you (a) write some more text lines in the text widget and (b) change the width of the shell: The text widget will become higher to show all the text.

What I need is a layout, that grabs minimal space for a complex composite (with multi line text widgets in it) but does not change it's hight after resizing the shell.

Can anybody help me?

Greetings,
Christian.



import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import de.chris_soft.fyllgen.Consts;

public class GuiExample {
public static void main(String[] args) {
Display display = Consts.display;
Shell shell = new Shell(display);
shell.setLayout(new FormLayout());

Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
text.setText("Small text");
FormData fd = new FormData();
fd.bottom = new FormAttachment(100, 0);
fd.left = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
text.setLayoutData(fd);

Button button = new Button(shell, 0);
button.setText("Just a button");
fd = new FormData();
fd.top = new FormAttachment(0, 0);
fd.bottom = new FormAttachment(text, -5, SWT.TOP);
fd.left = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
button.setLayoutData(fd);

shell.open();

// Warten bis TopLevel-Shell geschlossen wird
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}

display.dispose();
}
}
Re: Layout problem when resizing shell [message #721544 is a reply to message #721320] Fri, 02 September 2011 05:13 Go to previous messageGo to next message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
Why to use a FormLayout for such a simple configuration..
why not use GridLayout(in my opinion the universal layout as in universal gates)
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class GuiExample {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());

Button button = new Button(shell, 0);
button.setText("Just a button");

button.setLayoutData(new GridData(GridData.FILL_BOTH));

Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
text.setText("Small text");

GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
layoutData.heightHint=20;
text.setLayoutData(layoutData);



shell.open();

// Warten bis TopLevel-Shell geschlossen wird
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}

display.dispose();
}
}


or if you prefer FormLayout then
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class GuiExample {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FormLayout());

Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
text.setText("Small text");
FormData fd = new FormData();
fd.bottom = new FormAttachment(100, 0);
fd.left = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
//[b]the prefered height[/b]
fd.height=20;
text.setLayoutData(fd);

Button button = new Button(shell, 0);
button.setText("Just a button");
//[b]Always create new if your layour data changes[/b]
FormData fd1 = new FormData();
fd1.top = new FormAttachment(0, 0);
fd1.bottom = new FormAttachment(text, -5, SWT.TOP);
fd1.left = new FormAttachment(0, 0);
fd1.right = new FormAttachment(100, 0);

button.setLayoutData(fd1);

shell.open();

// Warten bis TopLevel-Shell geschlossen wird
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}

display.dispose();
}
};




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

[Updated on: Fri, 02 September 2011 05:20]

Report message to a moderator

Re: Layout problem when resizing shell [message #721556 is a reply to message #721544] Fri, 02 September 2011 06:01 Go to previous message
christian.packenius is currently offline christian.packenius
Messages: 2
Registered: September 2011
Junior Member
Hi vijay,

thanks for your answer! I will try out your suggestions.

Bye,
Christian.

Previous Topic:enable overwrite in text widget
Next Topic:Detect drop location from DND event
Goto Forum:
  


Current Time: Thu Oct 23 15:22:31 GMT 2014

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

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