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.
-
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-449Jan 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?– chamaJan 26, 2015 at 21:55
-
1If 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– Rüdiger HerrmannJan 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.– chamaJan 28, 2015 at 14:05
1 Answer
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.