Drawing a border around a Combo [message #640332] |
Sat, 20 November 2010 18:39 |
Jan Krakora Messages: 477 Registered: December 2009 Location: Prague |
Senior Member |
|
|
Hi,
I would like to draw a border around a Combo control. Here is my code
final Combo combo = new Combo(parent, SWT.DROP_DOWN);
combo.add("car");
combo.add("boat");
combo.add("ship");
combo.addPaintListener(new PaintListener() {
@Override
public void paintControl(final PaintEvent e) {
final Rectangle bounds = combo.getBounds();
e.gc.setAntialias(SWT.ON);
e.gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
e.gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
}
});
but unfortunately it draws two borders as you can see on the picture below
Can you tell me why? I would like to have only one border around the combo.
[Updated on: Sat, 20 November 2010 18:40] Report message to a moderator
|
|
|
|
Re: Drawing a border around a Combo [message #641218 is a reply to message #641105] |
Wed, 24 November 2010 14:38 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
This looks like a bug, I don't see why the lines you've pasted would result
in multiple borders being drawn.
The easiest workaround you can try is to give the Combo an additional
Composite parent and draw the border on it. The following snippet
demonstrates this:
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(200, 200, 200, 200);
shell.setLayout(new GridLayout());
final Composite composite = new Composite(shell, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginWidth = layout.marginHeight = 1;
composite.setLayout(layout);
composite.addPaintListener(new PaintListener() {
public void paintControl(final PaintEvent e) {
Rectangle bounds = composite.getBounds();
e.gc.setAntialias(SWT.ON);
e.gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
e.gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
}
});
final Combo combo = new Combo(composite, SWT.NONE);
combo.add("car");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Grant
"Behnil" <behnil@centrum.cz> wrote in message
news:icilvr$bno$1@news.eclipse.org...
> Nobody knows??
|
|
|
Powered by
FUDForum. Page generated in 0.03344 seconds