Solved

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

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now