Problem creating my own widget [message #455479] |
Mon, 16 May 2005 19:36 |
Philippe Larouche Messages: 14 Registered: July 2009 |
Junior Member |
|
|
Hello guys, I'm trying to create a new widget using SWT, but I have a major
problem. I want to add a button to my widget and I want it to be as wide as
the container. No matter which layoutdata i'm using, the button is always
the same width. Can someone help me and explain to me how layouts work in a
widget? Here my widget code:
public class SlidingViewer extends Composite
{
private Vector<Button> buttons = new Vector<Button>();
private ArrayList<Viewer> viewers = new ArrayList<Viewer>();
Color background;
public SlidingViewer(Composite parent, int style)
{
super(parent, style);
background = new Color(null,0,0,255);
setBackground(background);
addListener(SWT.Dispose, new Listener()
{
public void handleEvent(Event e)
{
onDispose();
}
});
addListener(SWT.RESIZE, new Listener()
{
public void handleEvent(Event e)
{
onResize();
}
});
GridLayout layout2 = new GridLayout();
layout2.numColumns = 1;
layout2.horizontalSpacing = 0;
layout2.marginHeight =0;
layout2.marginWidth = 0;
layout2.verticalSpacing = 0;
super.setLayout(layout2);
GridData gridData2 = new GridData();
gridData2.grabExcessHorizontalSpace = true;
gridData2.grabExcessVerticalSpace = true;
gridData2.horizontalAlignment = GridData.FILL;
gridData2.verticalAlignment = GridData.FILL;
setLayoutData(gridData2);
Button surveyButton = new Button(this, SWT.TOGGLE);
surveyButton.setText("Test");
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.heightHint = 25;
surveyButton.setLayoutData(gridData);
buttons.add(surveyButton);
}
protected void onDispose()
{
if(background != null)
background.dispose();
}
}
Thanks
Phil
|
|
|
Re: Problem creating my own widget [message #455551 is a reply to message #455479] |
Tue, 17 May 2005 07:05 |
Eclipse User |
|
|
|
Originally posted by: akan.aiqa.com
Philippe Larouche wrote:
> Hello guys, I'm trying to create a new widget using SWT, but I have a major
> problem. I want to add a button to my widget and I want it to be as wide as
> the container. No matter which layoutdata i'm using, the button is always
> the same width. Can someone help me and explain to me how layouts work in a
> widget? Here my widget code:
>
You can use FillLayout (or FormLayout as I always prefer) for the widget
you create and fill the composite with the button. You can find examples
at the net.
FormData button1Data = new FormData ();
button1Data.left = new FormAttachment (0, 0);
button1Data.right = new FormAttachment (100, 0);
button1Data.top = new FormAttachment (0, 0);
button1Data.bottom = new FormAttachment (100, 0);
button1.setLayoutData (button1Data);
aiQa
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03795 seconds