Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Customizing Eclipse RCP applications

Techniques to use with SWT and JFace

Scott Delap (scott@clientjava.com), Desktop/Enterprise Java Consultant
Scott Delap is president of Rich Client Solutions Inc., a software consulting firm focusing on technologies such as Swing, Eclipse RCP, GWT, Flex, and Open Laszlo. He is actively involved in the Java community, speaking at events such as NFJS, QCon and JavaOne. He is also the Java editor of InfoQ.com and runs ClientJava.com, a portal focused on desktop Java development.
Annas Andy Maleh (andy@obtiva.com), Consultant, MichaelDKelly.com
Annas "Andy" Maleh is a consultant at Obtiva Corp., a firm that specializes in Eclipse RCP development, Ruby on Rails development and training, and helping teams transition to Agile methodologies. He is currently involved with an Eclipse RCP project to build a custom CRM application for an international corporation. He works on a team that follows eXtreme Programming practices, programs professionally in Java and Ruby, and participates in work relating to UI design enhancement. At EclipseWorld 2006, he gave two presentations relating to Eclipse RCP development. He is a Sun Certified Java Programmer who holds a bachelor's degree in computer science from McGill University.

Summary:  Most developers think that an Eclipse Rich Client Platform (RCP) application must look similar in nature to the Eclipse integrated development environment (IDE). This isn't the case, however. This tutorial will explain a number of simple techniques you can use with the Standard Widget Toolkit (SWT) and JFace to create applications that have much more personality than the Eclipse IDE.

Date:  27 Feb 2007
Level:  Intermediate PDF:  A4 and Letter (1058 KB | 40 pages)Get Adobe® Reader®

Activity:  27686 views
Comments:  

CTabFolder and CTabItem

Companies sometimes require further customizations, such as changing the tab colors to match the company's standard color theme. Because TabFolder and TabItem are native widgets, they aren't very customizable and may not satisfy all business customization needs. On the other hand, CTabFolder and CTabItem are custom-drawn counterparts that are customizable. CTabFolder includes all the customizations in TabFolder, along with a number of additions.

Tab height

You can make tabs stand out more by increasing their height. Alternatively, you can save space by decreasing their height. Both tasks can be accomplished using the setTabHeight method.


Figure 13. Simple CTabs
Simple CTabs

tabFolder.setTabHeight(25);

This technique can be used in conjunction with larger font sizes to make the tab titles really stand out.

Fancy look

You can give your tabs a fancy look that has round edges, just like the tabs used for editors and views in the Eclipse IDE by default. To do so, use the setSimple method and pass it a false Boolean value.


Figure 14. Fancy CTabs
Fancy CTabs

tabFolder.setSimple(false);

Border visibility

The rounded-tab border can be toggled off using the setBorderVisible method.


Figure 15. Border turned off
Border turned off

tabFolder.setBorderVisible(false);

Run the CTabFolderExample to see these properties in action.

Tabs can also have a number of their color properties modified. You can customize the background color of selected tabs to be a gradient formed from multiple colors. In addition, you can customize the foreground color of a selected tab to fit with the background color using the method setSelectionForeground. To demonstrate, open the CTabFolderExample in the Java editor. Add the code below after the construction of the CTabFolder.


Listing 11. A gradient background
                    
Display display = Display.getCurrent(); 
int colorCount = 3; 
Color[] colors = new Color[colorCount]; 
colors[0] = display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND); 
colors[1] = display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT); 
colors[2] = colors[0]; 
int[] percents = new int[colorCount - 1]; 
percents[0] = 4; 
percents[1] = 60; 
tabFolder.setSelectionBackground(colors, percents, true); 
tabFolder.setSelectionForeground(display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND)); 

Running the example results in a change in appearance similar to below.


Figure 16. 2-D tabs
2-D tabs

setSelectionBackground takes three parameters:

  • color[] array containing different colors involved in the gradient
  • int[] array containing the percentage that each color must occupy in the gradient; the last color percentage isn't specified explicitly, but is implied
  • boolean indicating whether the direction of the gradient is vertical (top to bottom) or horizontal (left to right)

setSelectionForeground takes one parameter representing the foreground color (text color) of the selected tab.

Note the use of system colors SWT.COLOR_TITLE_BACKGROUND, SWT.COLOR_TITLE_BACKGROUND_GRADIENT, and SWT.COLOR_TITLE_FOREGROUND. These are the operating system theme colors. Using them ensures that the application looks and feels like the platform it's running on. As a more extreme example, modify the colors array shown below. Running the example shows a tab similar to that below.


Listing 12. A rainbow gradient
                    
			Display display = Display.getCurrent(); 
            int colorCount = 5; 
            Color[] colors = new Color[colorCount]; 
            colors[0] = display.getSystemColor(SWT.COLOR_DARK_BLUE); 
            colors[1] = display.getSystemColor(SWT.COLOR_DARK_CYAN); 
            colors[2] = display.getSystemColor(SWT.COLOR_DARK_GREEN); 
            colors[3] = display.getSystemColor(SWT.COLOR_DARK_YELLOW); 
            colors[4] = display.getSystemColor(SWT.COLOR_DARK_RED); 
            int[] percents = new int[colorCount - 1]; 
            percents[0] = 20; 
            percents[1] = 20; 
            percents[2] = 20; 
            percents[3] = 20; 
            tabFolder.setSelectionBackground(colors, percents, true); 
            tabFolder.setSelectionForeground\
            (display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND));


Figure 17. Rainbow tabs
Rainbow tabs

Single tabs

Sometimes it's more visually appealing to show a single tab if the tab titles are long. This makes only one tab appear at a time; a drop-down lets users switch to other tabs. Modify the CTabFolderExample with the line of code below.

tabFolder.setSingle(true);

You should now see tabs appear similar to those shown in figures 19 and 20.


Figure 18. Single tab
Single tab


Figure 19. Single tab showing other tabs
Single tab showing other tabs

9 of 18 | Previous | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source
ArticleID=197254
TutorialTitle=Customizing Eclipse RCP applications
publish-date=02272007
author1-email=scott@clientjava.com
author1-email-cc=
author2-email=andy@obtiva.com
author2-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.