Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Control getSize() behaves different in Linux and Windows
Control getSize() behaves different in Linux and Windows [message #660959] Tue, 22 March 2011 14:08 Go to next message
Daniel Galdames is currently offline Daniel GaldamesFriend
Messages: 2
Registered: March 2011
Junior Member
Calling getSize() from a button contained in a ExpandItem returns (0,0) on Linux. Doing the same on Windows returns (x,y) where x,y = preferred size. What should be the right value.

Code example:
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;

public class Snippet {
static ExpandBar bar;
static Image image;
static MenuItem item;

public static void main(String[] args) {
Shell shell = new Shell();
Display display = shell.getDisplay();
shell.setLayout(new FillLayout());
shell.setText("ExpandBar Example");

Menu menubar = new Menu(shell, SWT.BAR);
shell.setMenuBar(menubar);
MenuItem fileItem = new MenuItem(menubar, SWT.CASCADE);
fileItem.setText("&File");
Menu submenu = new Menu(shell, SWT.DROP_DOWN);
fileItem.setMenu(submenu);
item = new MenuItem(submenu, SWT.PUSH);
item.setText("New ExpandItem");

bar = new ExpandBar(shell, SWT.V_SCROLL);
image = display.getSystemImage(SWT.ICON_QUESTION);

// First item
Composite composite = new Composite(bar, SWT.NONE);
Menu popupmenu = new Menu(shell, SWT.POP_UP);
MenuItem popupItem = new MenuItem(popupmenu, SWT.PUSH);
popupItem.setText("Popup");
composite.setMenu(popupmenu);

GridLayout layout = new GridLayout(2, false);
layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
layout.verticalSpacing = 10;
composite.setLayout(layout);
Label label = new Label(composite, SWT.NONE);
label.setImage(display.getSystemImage(SWT.ICON_ERROR));
label = new Label(composite, SWT.NONE);
label.setText("SWT.ICON_ERROR");
label = new Label(composite, SWT.NONE);
label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)) ;
label = new Label(composite, SWT.NONE);
label.setText("SWT.ICON_INFORMATION");
label = new Label(composite, SWT.NONE);
label.setImage(display.getSystemImage(SWT.ICON_WARNING));
label = new Label(composite, SWT.NONE);
label.setText("SWT.ICON_WARNING");
label = new Label(composite, SWT.NONE);
label.setImage(display.getSystemImage(SWT.ICON_QUESTION));
label = new Label(composite, SWT.NONE);
label.setText("SWT.ICON_QUESTION");
ExpandItem item1 = new ExpandItem(bar, SWT.NONE);
item1.setText("What is your favorite icon");
item1.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
item1.setControl(composite);
item1.setImage(image);

// Second item
composite = new Composite(bar, SWT.NONE);
layout = new GridLayout(2, true);
layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
layout.verticalSpacing = 10;
composite.setLayout(layout);
Button button1 = new Button(composite, SWT.PUSH);
button1.setText("Button 1");
Button button2 = new Button(composite, SWT.PUSH);
button2.setText("Button 2");

ExpandItem item0 = new ExpandItem(bar, SWT.NONE);
item0.setText("What is your favorite button");
item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
item0.setControl(composite);
item0.setImage(image);
item0.setExpanded(true);

item.addListener(SWT.Selection, new Listener(){
@Override
public void handleEvent(Event e) {
ExpandItem item2 = new ExpandItem(bar, SWT.NONE);
Composite composite = new Composite(bar, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
composite.setLayout(layout);
Label label = new Label(composite, SWT.NONE);
label.setText("What is your name?");
Composite pcomposite = new Composite(composite, SWT.NONE);
Text text = new Text(pcomposite, SWT.NONE);
item2.setText("New Question");
text.pack();
composite.pack();
Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
item2.setHeight(size.y);
item2.setControl(composite);
item2.setImage(image);
item2.setExpanded(true);
}
});

bar.setSpacing(8);
shell.setSize(400, 550);
shell.open();
System.out.println("------------------------------");
System.out.println("getSize: " + button1.getSize());
System.out.println("getBounds: " + button1.getBounds());
System.out.println("computeSize: "
+ button1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
System.out.println("getLocation: " + button1.getLocation());

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

}
Re: Control getSize() behaves different in Linux and Windows [message #661165 is a reply to message #660959] Wed, 23 March 2011 12:32 Go to previous message
Lakshmi ShanmugamFriend
Messages: 276
Registered: July 2009
Location: India
Senior Member
Hi,
getSize() should return the actual size of the control. This looks like a bug on Linux. Please open a bug with SWT here--> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=SWT

Thanks.


Lakshmi P Shanmugam
Previous Topic:Grouping menus in context menu
Next Topic:Fixing SWT Shell width and having adjustable height
Goto Forum:
  


Current Time: Sun Mar 29 21:24:40 GMT 2020

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

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

Back to the top