Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-11-22
4
Medium Priority
?
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Make the most of your online learning experience.
Simple Linear Regression
Introduction to Processes
Suggested Courses

721 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