Hi j2Se!
Ich muss Dich leider enttäuschen!
hab schon gehört dass das bei AWT/Swing funktionieren soll.
Leider war das aber eine SWT Frage
Während ich auf die Antwort gewartet habe
bin ich über den eclipse bug 23837 gestolpert
https://bugs.eclipse.org/bugs/show_bug.cgi?id=23837
anscheinend ist das ein Windows Bug!
Windows behilft sich im Dot Net damit, dass sie dafür den ARROW Button verwenden.
Ich benutze aber Linux und dort funktioniert aber nicht mal das
aber vielleicht könnte mir da ja jemand mit dem Workaround, der auch im Link vom Bug angeführt ist, weiter helfen.
Bei mir will der irgendwie nicht funktionieren.
Ich hab ihn bei der Definition versucht

da zeigt es überhaupt keine Wirkung
dann hab ich es in einem paintListener versucht
wobei ich GC selbst erzeugt habe wie im Beispiel

da wird der Text weiter nach hinten verschoben
und davor ein weißes bzw. durchsichtiges Rechteck gezeichnet
und dann hab ich's noch versucht indem ich den GC
richtiger weise aus dem Widget gezogen habe

da wird mir der Button zwar rot gezeichnet
ist aber wohl eher das ganze Feld
weil Button sieht man da keinen mehr
und noch dazu kann ich ihn nicht mehr drücken
folgenden Code habe ich modifiziert aus dem Workaround
Java:
component.addPaintListener(new PaintListener()
{
@override
public void paintControl(PaintEvent ev)
{
Control control= (Control)ev.widget;
Button button= (Button)ev.widget;
Display display= ev.display;
//Control control= component;
//Button button= (Button)component;
//Display display= component.getDisplay();
String text = button.getText();
int type= button.handle;
GC gc;
Font font;
FontData fontData;
Color foreground= display.getSystemColor(SWT.COLOR_BLACK);
//Color foreground = control.getForeground();
Color background = display.getSystemColor(SWT.COLOR_RED);
Image original;
Rectangle rect= control.getBounds();
char textArray[]= text.toCharArray();
int x = 0;
int y = 0;
int width = rect.width;
int height = rect.height;
int fontHeight, fontWidth;
int ximg, yimg;
if (width == 0)
width = 1;
if (height == 0)
height = 1;
button.setImage(new Image(control.getParent().getDisplay(), width, height));
original = button.getImage();
ImageLoader loader= new ImageLoader();
loader.data= new ImageData[] {original.getImageData()};
loader.save("/home/kollia/button.jpg", SWT.IMAGE_JPEG);
gc = new GC(original); // <- GC selbst erzeugt
//gc = ev.gc; // <- GC aus dem Widget gezogen
gc.setForeground(foreground);
gc.setBackground(background);
gc.drawRectangle(x, y, width, height);
gc.fillRectangle(x, y, width, height);
gc.setFont(button.getFont());
font= button.getFont();
fontData= font.getFontData()[0];
fontHeight = fontData.getHeight();
fontWidth= 0;
for (char c : textArray)
fontWidth+= gc.getCharWidth(c);
//ximg = (x + width) / 2 - fontSize * text.length() / 3;
ximg= 4;//(x + width) / 2 - fontWidth / 2;
yimg = (y + height) / 2 - fontHeight * 3 / 4;
System.out.println(ximg +"= ("+x+" + "+width+") / 2 - "+fontWidth+" / 2");
gc.drawText(text, ximg > 4 ? ximg : 4, yimg > 4 ? yimg : SWT.DRAW_TRANSPARENT | SWT.DRAW_MNEMONIC);
gc.dispose();
if(!button.isEnabled())
{
Image iDisable = new Image(button.getParent().getDisplay(), original, SWT.IMAGE_DISABLE);
button.setImage(iDisable);
}
}
});
Ok, eigentlich habe ich mich ja schon damit abgefunden dass ich den Button nicht rot zeichnen kann.
Aber dann möchte ich wenigstens die Schriftfarbe setzen
könnte das sich vielleicht jemand ansehen!?
was läuft da schief?
;-)pcAlko