Search code examples
javaswtrcp

RCP Application/SWT Label BOLD


It is a RCP application, you have a (a) LIST of Names, it is downloaded by means of a FOR loop.

That is to say they are Menu items and that they are located to the left of the screen with its respective layer (composite).

Now, this works, the difficulty / what is needed here is that when you double-click on an Item it receives a "SWT.BOLD" character and when you click on another Item, the previous one receives SWT.NONE and the chosen one SWT.BOLD. A highlighten ....

Here Code:

for (int i = 0; i < 2; i++) {
        final Label l1 = neueLabel(shell, "label "+i, i);
        l1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDoubleClick(MouseEvent e) {
                if(e.button==1)
                    l1.setFont(SWTResourceManager.getFont("Segoe UI", 9, 
                               SWT.BOLD));
            }
        });
    } 

Tanks


Solution

  • You need to save your currently highlighted label and reset its font. Assuming your class has a private Label current; your overwritten method may look like

    if (e.button == 1) {
        if (current != null)
            current.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.NONE));
        l1.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
        current = l1;
    }