Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » the controls in a row should not be centered vertically. why??(RowLayout)
icon12.gif  the controls in a row should not be centered vertically. why?? [message #898713] Fri, 27 July 2012 10:25 Go to next message
zhang lei is currently offline zhang leiFriend
Messages: 22
Registered: July 2012
Junior Member
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
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 RowLayoutExample {
	Display d;
	Shell s;
	public RowLayoutExample(){
		d = new Display();
		s = new Shell();
		s.setSize(800, 600);
		s.setText("A RowLayoutExample");
		RowLayout r1 = new RowLayout();
		r1.wrap = false;
		r1.pack = false;
		[color=red]r1.center = true;[/color]
		r1.spacing = 0;
		s.setLayout(r1);
		final Text text = new Text(s,SWT.MULTI|SWT.BORDER);
		final Button b = new Button(s,SWT.NONE);
		b.setText("ok");
		final Button b1 = new Button(s,SWT.NONE);
		b1.setText("cancel");
		s.open();
		while (!s.isDisposed()) {
			if (!d.readAndDispatch()) {
				d.sleep();
			}
		}
		d.dispose();
	}
	public static void main(String[] args) {
		new RowLayoutExample();
	}
}

I have two questions:
1.the controls in a row should not be centered vertically. why??
2.if the pack is set false,the text control's cursor could not display in the bottom.why???
Re: the controls in a row should not be centered vertically. why?? [message #898721 is a reply to message #898713] Fri, 27 July 2012 10:56 Go to previous messageGo to next message
zhang lei is currently offline zhang leiFriend
Messages: 22
Registered: July 2012
Junior Member
I have set the center variable true,but the controls could not display in the center.The question bothered me for a long time...
Re: the controls in a row should not be centered vertically. why?? [message #899228 is a reply to message #898721] Tue, 31 July 2012 07:38 Go to previous messageGo to next message
zhang lei is currently offline zhang leiFriend
Messages: 22
Registered: July 2012
Junior Member
why no people could answer my question ? help me. thanks!
Re: the controls in a row should not be centered vertically. why?? [message #899236 is a reply to message #899228] Tue, 31 July 2012 08:06 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Quote:
1.the controls in a row should not be centered vertically. why??

What does it mean? Why are you thinking the controls should not be centered vertically?
Quote:
2.if the pack is set false,the text control's cursor could not display in the bottom.why???

I don't understand again.
Re: the controls in a row should not be centered vertically. why?? [message #899464 is a reply to message #899236] Wed, 01 August 2012 01:46 Go to previous messageGo to next message
zhang lei is currently offline zhang leiFriend
Messages: 22
Registered: July 2012
Junior Member
1.I think that set the center variable true value, the controls should be center verticaly,my english is pool ,please see the picture file.
index.php/fa/10960/0/
index.php/fa/10959/0/

Re: the controls in a row should not be centered vertically. why?? [message #899465 is a reply to message #899464] Wed, 01 August 2012 01:49 Go to previous messageGo to next message
zhang lei is currently offline zhang leiFriend
Messages: 22
Registered: July 2012
Junior Member
The cursor could not display at the bottom,see the next picture.
index.php/fa/10961/0/

Re: the controls in a row should not be centered vertically. why?? [message #899557 is a reply to message #899465] Wed, 01 August 2012 12:20 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Ad 1) But they are centered vertically.
Ad 2) The cursor in a Text is as high as the font of that Text.
Re: the controls in a row should not be centered vertically. why?? [message #899602 is a reply to message #899557] Wed, 01 August 2012 14:41 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

The vertical centering happens _within the row of widgets_, not relative
to the parent widget (the Shell). So if your Buttons each had a height
of 100 and your Text had a height of 40, then the Text would be placed
at y=30 by the layout ((100 - 40) / 2 = 30).

To do what you want you're asking about you need an additional Composite
that is centered on the Shell, and set the layout on it. In your
snippet this would look like:

public RowLayoutExample() {
Display d = new Display();
Shell s = new Shell();
s.setSize(800, 600);
s.setText("A RowLayoutExample");
s.setLayout(new GridLayout());
Composite c = new Composite(s, SWT.NONE);
c.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER |
GridData.GRAB_VERTICAL));
RowLayout r1 = new RowLayout();
r1.wrap = false;
r1.pack = false;
r1.center = true;
r1.spacing = 0;
c.setLayout(r1);
new Text(c,SWT.MULTI|SWT.BORDER);
new Button(c,SWT.NONE).setText("ok");
new Button(c,SWT.NONE).setText("cancel");
s.open();
while (!s.isDisposed()) {
if (!d.readAndDispatch()) {
d.sleep();
}
}
d.dispose();
}

Grant


On 8/1/2012 8:20 AM, Jan Krakora wrote:
> Ad 1) But they are centered vertically.
> Ad 2) The cursor in a Text is as high as the font of that Text.
Re: the controls in a row should not be centered vertically. why?? [message #899705 is a reply to message #899602] Thu, 02 August 2012 03:04 Go to previous message
zhang lei is currently offline zhang leiFriend
Messages: 22
Registered: July 2012
Junior Member
Hi.
I am glad to see the answer .thank you,Jan Krakora and Grant Gayed.your code is so cool Razz ,I have find the way through your help.The next is the snippet of the code which I need.Thank you for your help.
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
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;
import org.eclipse.swt.widgets.Text;


public class RowLayoutExample {

	public RowLayoutExample() {
		Display d = new Display();
		Shell s = new Shell();
		s.setSize(800, 600);
		s.setText("A RowLayoutExample");
		s.setLayout(new GridLayout());
		Composite c = new Composite(s, SWT.BORDER);
		c.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER | 
		GridData.GRAB_HORIZONTAL));
		RowLayout r1 = new RowLayout();
		r1.wrap = false;
		r1.pack = false;
		r1.center = true;
		r1.spacing = 0;
		c.setLayout(r1);
		Text text = new Text(c,SWT.SINGLE|SWT.BORDER);
		Font initialFont = text.getFont();
		FontData[] fontData = initialFont.getFontData();
	    for (int i = 0; i < fontData.length; i++) {
	        fontData[i].setHeight(18);
	      }
		Font newFont = new Font(d, fontData);
		text.setFont(newFont);
		new Button(c,SWT.NONE).setText("ok");
		new Button(c,SWT.NONE).setText("cancel");
		s.open();
		while (!s.isDisposed()) {
		if (!d.readAndDispatch()) {
		d.sleep();
		}
		}
		d.dispose();
		}
public static void main(String[] args) {
	new RowLayoutExample();
}
}
Previous Topic:OLE Automation read shared email inbox
Next Topic:Scroll bar appears in Win 7 and not in Win XP
Goto Forum:
  


Current Time: Thu Mar 28 10:03:40 GMT 2024

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

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

Back to the top