[SWT] Buttonfarbe

Ronin-Jay

Erfahrenes Mitglied
Hallo zusammen,

irgendwie habe ich gerade ne Blockade. Normalerweise kann man ja mittels .setForeground(color) die Textfarbe eine Textfeldes ändern. Ich würde jetzt aber gerne die Textfarbe eines Buttons ändern, nur leider scheitere ich daran.

So sieht es aus:
Java:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
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.Shell;

public class buttonForeground {
	
	Display display;
	protected Shell shell;

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

	/**
	 * Open the window
	 */
	public void open() {
		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();
		shell.setLayout(new GridLayout());
		shell.setSize(500, 375);
		shell.setText("SWT Application");

		final Button button = new Button(shell, SWT.PUSH);
		button.setSelection(true);
		button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
			}
		});
		Color red = new Color(display,255,0,0);
		//button.setForeground(red);
		button.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED));
		button.setText("button");
		//
	}

}

Jedoch bleibt die Farbe des Buttons standard....
Habs unter XP Pro mit klassischem und Xp-Stil, sowie Windows 2000 ausprobiert.... - kein farbiges Ergebnis. :confused:

Entferne mal bitte jemand das Brett vor meinem Kopf. :rolleyes:
 

Neue Beiträge

Zurück