Solved

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

Posted on 2013-11-22
4
343 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 35

Accepted Solution

by:
mccarl earned 500 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 35

Assisted Solution

by:mccarl
mccarl earned 500 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

821 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