|
|
|
|
|
Re: How do I change a button background color ??? [message #449720 is a reply to message #449552] |
Fri, 28 January 2005 03:41  |
Eclipse User |
|
|
|
Originally posted by: gilblais.yahoo.com
Hi Armin - thank you, but that result was the same. Here is the code snippet
I am using.
--- cut here ---
package UI;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
public class PB_xxx implements INTERFACES.IF {
public static void main(String[] args) {
new PB_xxx().runTHIS(new String[] { });
}
void runTHIS(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(395,80);
final Button btnCAS = new Button(shell, SWT.NONE);
btnCAS.setSelection(true);
btnCAS.setText("Contracting Administration Screen");
btnCAS.setForeground(Display.getCurrent().getSystemColor(SWT .COLOR_RED));
btnCAS.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_RED));
// left,top,width,height
btnCAS.setBounds(10, 10, 360, 30);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}
}
--- end ---
"Armin Roth" <armin.roth@visana.ch> wrote in message
news:ct83vh$jdu$1@www.eclipse.org...
> Hi Gil
>
> Use this instead:
>
> final Button btnCAS = new Button(shell, SWT.NONE);
> btnCAS.setSelection(true);
> btnCAS.setBackground(Display.getCurrent().getSystemColor(SWT .COLOR_RED));
>
> the .getParent() made you change the buttons parent (the shell you used
> for constructing the button) background color.
>
> Be aware of that Display.getCurrent() may deliver null if this code is
> running outside of the SWT-Thread.
>
> Kind regards,
> Armin Roth
>
>
> Gil Blais wrote:
>
>> Matt - thank you, but when I do that I end up with the entire display
>> having its color changed instead of just the button. Here are the lines
>> of code:
>> final Button btnCAS = new Button(shell, SWT.NONE);
>> btnCAS.setSelection(true);
>>
> btnCAS.getParent().setBackground(Display.getCurrent().getSys temColor(SWT.COLOR_RED));
>
>
>
>> "Matthew Ma" <matthew1801@hotmail.com> wrote in message
>> news:ct7nqn$v56$1@www.eclipse.org...
>>> Button is inherited from Control, so you can use the setBackground(Color
>>> color) function - under Control - to change the background color of the
>>> button.
>>>
>>> Matthew
>>>
>>>
>>> "Gil Blais" <gilblais@yahoo.com> wrote in message
>>> news:ct7n84$sms$1@www.eclipse.org...
>>>> I cannot seem to display anything but a gray button with black
>>>> lettering -
>>>> any help is well appreciated. Thanks, Gil Blias
>>>>
>>>>
>>>
>>>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03084 seconds