Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to draw a gradient background color in a CLabel in JAVA SWT?

Posted on 2013-11-22
4
Medium Priority
?
362 Views
Last Modified: 2013-11-24
Hi,
I need to change the color of a SWT CLabel from dark blue to light blue.

Can you please tell me how I can fade from dark blue to a lighter blue in this CLabel?

This is the code I have that make it dark blue color:

        GridData gridDataBanner = new GridData(SWT.FILL, SWT.FILL, true, false);

        
        CLabel banner = new CLabel(shell, SWT.CENTER);
        Color MWBlue = new Color (shell.getDisplay(), 62, 87, 189);
        banner.setBackground(MWBlue); 
        
        FontData fontData = banner.getFont().getFontData()[0];
        Font fontBanner = new Font(shell.getDisplay(), new FontData(fontData.getName(), 10, SWT.BOLD));
        banner.setFont(fontBanner);
        banner.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
        

        banner.setText("\nSOMETHING \n ");
        banner.setLayoutData(gridDataBanner);

Open in new window


Thanks,
0
Comment
Question by:Tolgar
  • 2
  • 2
4 Comments
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 total points
ID: 39671333
Replace lines 5 & 6 with this...
banner.setBackground(new Color[] { display.getSystemColor(SWT.COLOR_DARK_BLUE), display.getSystemColor(SWT.COLOR_BLUE) }, new int[] { 100 });

Open in new window

Obviously, you can use different colors, etc if you want. You can also do a bit more complex gradients with this method, if you desire. The javadoc alludes to some things you can do, but it might not be obvious as to what it's doing, so if you want more info, just ask!
0
 

Author Comment

by:Tolgar
ID: 39671609
Can we do this from top to bottom?
0
 
LVL 36

Assisted Solution

by:mccarl
mccarl earned 2000 total points
ID: 39672161
Use this instead then...
banner.setBackground(new Color[] { display.getSystemColor(SWT.COLOR_DARK_BLUE), display.getSystemColor(SWT.COLOR_BLUE) }, new int[] { 100 }, true);

Open in new window

0
 

Author Comment

by:Tolgar
ID: 39672957
Can you please take look at this follow up question?

http://www.experts-exchange.com/Programming/Languages/Java/Q_28302146.html
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Starting up a Project
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question