Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWT Controls with predefined styles

Tags:

swt

I want to have in my SWT project controls (Button-s, Text-s, etc) with predefined styles. My first idea was to extend for example org.eclipse.swt.widgets.Text class, set some settings and use that new classes instead of original, but get org.eclipse.swt.SWTException: Subclassing not allowed exception. How to do that right ?

like image 248
marioosh Avatar asked Mar 05 '12 12:03

marioosh


2 Answers

You have to override checkSubclass method to do nothing, otherwise it will complain that subclassing not allowed - because usually you shouldn't really override standard components.

@Override
protected void checkSubclass() {
    // Disable the check that prevents subclassing of SWT components
}

You also should consider building custom widgets containing primitive controls using delegation. For example you can build MyText which will contain Text widget inside with custom setup.

Thing to remember is SWT provides standard controls which looks natively on each on platform. Anyway polishing standard components is still allowed and even a must in production software.

like image 96
Vladimir Avatar answered Dec 31 '22 11:12

Vladimir


See the SWT Faq for this concern. There you'll find also a link howto write custom widgets

like image 36
Tom Seidel Avatar answered Dec 31 '22 13:12

Tom Seidel