[SWT] Button mit Image - Win2k vs. XP

Ronin-Jay

Erfahrenes Mitglied
Hallo zusammen,

ich habe gerade ein merkwürdiges Phänomen entdeckt. Ich habe einen Button mit Image und Beschriftung. Wenn ich mir meine Applikation mit XP Pro/Home/Embedded anschaue, erscheint der Button so wie er soll - nämlich mit Beschriftung & Image. Unter Windows Windows 2000 wird allerdings nur das Image, nicht aber die Beschriftung gezeigt. Hat einer von Euch ne Idee, woran es liegen könnte? Windows XP wurde sowohl mit 2000-Stil als auch im XP Stil getestet....

Habe auch noch rausgefunden, dass er mir beim Button mit Image nur genau das letzte der beiden gesetzten Elemente anzeigt, sprich, wird zuerst der Text und dann das Bild gesetzt, zeigt er nur das Bild auf dem Button an. - entsprechend umgekehrt.

Hier mal ein Beispiel schnell mit einem GUI-Builder zusammengeklickt:
Java:
package buttonExample;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class ImageButton {

	protected Shell shell;
	Image img;

	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			ImageButton window = new ImageButton();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window
	 */
	public void open() {
		final Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	/**
	 * Create contents of the window
	 */
	protected void createContents() {
		shell = new Shell();
		img = new Image(Display.getDefault(),				
						ImageButton.class.getResourceAsStream("eclipse.png"));
		final GridLayout gridLayout = new GridLayout();
		gridLayout.makeColumnsEqualWidth = true;
		gridLayout.numColumns = 3;
		shell.setLayout(gridLayout);
		shell.setSize(0, 0);
		shell.setText("SWT Application");

		final Group beschriftungGroup = new Group(shell, SWT.NONE);
		beschriftungGroup.setLayout(new GridLayout());
		beschriftungGroup.setText("Beschriftung");
		final GridData gd_beschriftungGroup = new GridData(SWT.FILL, SWT.FILL, false, true);
		beschriftungGroup.setLayoutData(gd_beschriftungGroup);

		final Button nurBeschriftungButton = new Button(beschriftungGroup, SWT.NONE);
		nurBeschriftungButton.setLayoutData(getButtonGridData());
		nurBeschriftungButton.setText("nur Beschriftung");
		new Label(shell, SWT.NONE);

		final Group imageGroup = new Group(shell, SWT.NONE);
		imageGroup.setLayout(new GridLayout());
		imageGroup.setText("Image");
		final GridData gd_imageGroup = new GridData(SWT.FILL, SWT.FILL, false, true);
		imageGroup.setLayoutData(gd_imageGroup);

		final Button button_2 = new Button(imageGroup, SWT.NONE);
		button_2.setImage(img);
		button_2.setLayoutData(getButtonGridData());
		new Label(shell, SWT.NONE);

		final Group beschriftungImageGroup = new Group(shell, SWT.NONE);
		beschriftungImageGroup.setLayout(new GridLayout());
		beschriftungImageGroup.setText("Beschriftung & Image");
		final GridData gd_beschriftungImageGroup = new GridData(SWT.FILL, SWT.FILL, true, true);
		beschriftungImageGroup.setLayoutData(gd_beschriftungImageGroup);

		final Button imageBeschriftungButton = new Button(beschriftungImageGroup, SWT.NONE);
		imageBeschriftungButton.setImage(img);
		imageBeschriftungButton.setLayoutData(getButtonGridData());
		imageBeschriftungButton.setText("Text + Image");

		final Button button = new Button(beschriftungImageGroup, SWT.NONE);
		button.setText("Image + Text");
		button.setImage(img);
		button.setLayoutData(getButtonGridData());
		new Label(shell, SWT.NONE);
		
		shell.pack();
		shell.setMinimumSize(530,300);
		//
	}
	
	
	public GridData getButtonGridData() {
		GridData gd = new GridData(SWT.CENTER, SWT.CENTER, true, true);
		gd.widthHint  = 150;
		gd.heightHint =  50;
		return gd;
	}//getTsButtonRowData()

}
 

Neue Beiträge

Zurück