Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How do I change a button background color ???
How do I change a button background color ??? [message #449543] Wed, 26 January 2005 09:17 Go to next message
Eclipse UserFriend
Originally posted by: gilblais.yahoo.com

I cannot seem to display anything but a gray button with black lettering -
any help is well appreciated. Thanks, Gil Blias
Re: How do I change a button background color ??? [message #449544 is a reply to message #449543] Wed, 26 January 2005 09:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: matthew1801.hotmail.com

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
>
>
Re: How do I change a button background color ??? [message #449550 is a reply to message #449544] Wed, 26 January 2005 10:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gilblais.yahoo.com

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
>>
>>
>
>
Re: How do I change a button background color ??? [message #449552 is a reply to message #449550] Wed, 26 January 2005 12:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: armin.roth.visana.ch

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
>>>
>>>
>>
>>
Re: How do I change a button background color ??? [message #449709 is a reply to message #449543] Fri, 28 January 2005 00:49 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
You can't on Windows. Nobody can. The operating system doesn't support it.

"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
>
>
Re: How do I change a button background color ??? [message #449720 is a reply to message #449552] Fri, 28 January 2005 08:41 Go to previous message
Eclipse UserFriend
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
>>>>
>>>>
>>>
>>>
>
>
Previous Topic:DnD: Outlook email to SWT table
Next Topic:How to undo from a Text??
Goto Forum:
  


Current Time: Fri Nov 15 21:34:15 GMT 2019

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

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

Back to the top