Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

776 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