problem aligning both image/text inside a button [message #331734] |
Thu, 18 September 2008 17:15 |
Eclipse User |
|
|
|
(sorry, got no response from swt forum, so post it here - really need to
figure this out)
Hi, I can left-align text or image using Button.setAlignment(SWT.LEFT)
method, but if a button has both image and text, setAlignment stops
working. I am wondering if there is any solution to this problem or that
this is a bug. Thanks in advance.
Here is a simple test problem when both image and text are set. If you
comment out the line with image setting or text setting, either image or
text can be left-aligned. But when bother are set, they are center-aligned
instead of left-aligned:
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class TestButtonImageText {
public static void main(String[] args) {
Display display = new Display();
Image image = display.getSystemImage(SWT.ICON_QUESTION);
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
Button button = new Button(shell, SWT.PUSH | SWT.LEFT);
button.setText("Button");
button.setImage(image);
button.setAlignment(SWT.LEFT);
GridData gd = new GridData();
gd.widthHint = 130;
gd.heightHint = 35;
button.setLayoutData(gd);
shell.setSize(300, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.02918 seconds