2

I keep asking questions about customizing the features of SWT (see this question I asked last week). Instead of asking a new question for every feature I want to override, is there any place I can look to find it myself? I'm open to looking at code, documentation, or really anything that can point me in the right direction.

4
  • The SWT source code is readily available as part of the Eclipse SDK. However as it has a lot of native method calls and is completely different for each platform it is not easy to read.
    – greg-449
    Jan 26, 2015 at 21:54
  • So aside from the source code, there is nowhere to look? And since the source code is hard to read, I'm stuck asking questions on every feature?
    – chama
    Jan 26, 2015 at 21:55
  • 1
    If you find yourself wanting to override SWT features often, then maybe SWT isn't the right UI toolkit for your use case. SWT is a thin layer on top of the UI facilities of the operation system. To be portable,it usually implements the least common denominator of all supported platforms. Before asking questions you may want to look here, or here Jan 27, 2015 at 7:37
  • It's more like customizing SWT features. Like I want to change the location of the arrow in a sorted table, get rid of the gray background that comes with being sorted, and make alternating row backgrounds for the table. All of these questions have been answered with "that is controlled by the OS and you can't change it". That made me wonder what I can customize in SWT.
    – chama
    Jan 28, 2015 at 14:05

1 Answer 1

0

The java documentation of most SWT widgets and features states if a class is not intended to be subclassed. So if you want to extend something or change a behavior of a class that is not intended to be subclassed, I would recommend e.g. to wrap the Widget in your own class with methods to mimic your intended behavior with the given functionalities.

For example the java documentation of SWT Combo says:

IMPORTANT: This class is not intended to be subclassed.

So I wrote the my own wrapper class:

public class VftCombo {

    Combo combo;

    public VftCombo(Composite parent, int style) {
        this.combo = new Combo(parent, style);
        disableKeyboardDropdownNavigation();
    }

    private void disableKeyboardDropdownNavigation() {
        this.combo.addKeyListener(new KeyListener() {
            @Override
            public void keyReleased(KeyEvent e) {
                if (e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.ARROW_UP) {
                    e.doit = false;
                }
            }

            @Override
            public void keyPressed(KeyEvent e) {
                if (e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.ARROW_UP) {
                    e.doit = false;
                }
            }
        });
    }

    public Combo getWidget() {
        return this.combo;
    }

    public void setItems(List<String> items) {
        // instead of using org.eclipse.swt.widgets.combo.setItems(String[] items)
    }
}

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.