Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

How to give color to toolbar borders in SWT?

How can I make the white borders of the toolbar the same color as the toolbar background color in SWT and put vertical black lines in between the toolbar groups?

I am sending a screen shot to show the white border lines.
white-borderline.png
0
Tolgar
Asked:
Tolgar
  • 2
2 Solutions
 
ValeriCommented:
ok. follow these steps:
1. every time you create a CustomToolBar create it in this way
CustomToolBar custToolBar12 = new CustomToolBar(compTB, SWT.FLAT, "preferences");
instead of
CustomToolBar custToolBar12 = new CustomToolBar(compTB, SWT.BORDER, "preferences");
the only difference is SWT.FLAT instead of SWT.BORDER. it will remove the borders of the toolbar groups.
2. after the toolbar groups you want to put vertical black lines. to do this after each one of the groups add this code:

Label verticalSepartor = new Label(compTB, SWT.SEPARATOR | SWT.SHADOW_OUT | SWT.VERTICAL);
        GridData sepGD1 = new GridData(GridData.FILL_VERTICAL);
        verticalSepartor.setLayoutData(sepGD1); verticalSepartor.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));

if you want you can capsulate this piece of code in different class to hava your code more readable.

P.S. if you have 3 toolbar groups and 2 vertival black line as separators after the first and the second toolbar group, you have to change GridLayout of the composite that represents your whole toolbar in this way:
GridLayout gridLayout1 = new GridLayout(5, false);
compTab1.setLayout(gridLayout1);
"5" because you have 3 groups and 3 lines. if you have 4 groups and 3 lines change it to 7.
0
 
TolgarAuthor Commented:
Ok. Perfect! This works. One minor question. Even though I used black as a color for the separators, it shows up as white. Do you have any idea why?

This is the code I use:

        Label verticalSepartor32 = new Label(compTB3, SWT.SEPARATOR | SWT.SHADOW_OUT | SWT.VERTICAL);
        GridData sepGD32 = new GridData(GridData.FILL_VERTICAL);
        verticalSepartor32.setLayoutData(sepGD32); verticalSepartor32.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));

Open in new window

0
 
ValeriCommented:
actually it's the shadow of the separator which always white. my mistake. in the above code just replace "SWT.SHADOW_OUT" with "SWT.SHADOW_NONE"
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now