Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » problem aligning both image/text inside a button
problem aligning both image/text inside a button [message #331734] Thu, 18 September 2008 17:15
Rick C. is currently offline Rick C.Friend
Messages: 9
Registered: July 2009
Junior Member
(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();
}
}
Previous Topic:A question about automatically build
Next Topic:Q regarding order of contributed menus to popup menus
Goto Forum:
  


Current Time: Wed Jul 17 15:38:41 GMT 2024

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

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

Back to the top