Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Drawing a border around a Combo(problem with drawing a simple border around a Combo control)
Drawing a border around a Combo [message #640332] Sat, 20 November 2010 13:39 Go to next message
Eclipse UserFriend
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

http://img200.imageshack.us/img200/1125/combotl.png

Can you tell me why? I would like to have only one border around the combo.

[Updated on: Sat, 20 November 2010 13:40] by Moderator

Re: Drawing a border around a Combo [message #641105 is a reply to message #640332] Wed, 24 November 2010 04:34 Go to previous messageGo to next message
Eclipse UserFriend
Nobody knows??
Re: Drawing a border around a Combo [message #641218 is a reply to message #641105] Wed, 24 November 2010 09:38 Go to previous message
Eclipse UserFriend
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??
Previous Topic:Long cells in table/tree - truncate from left?
Next Topic:Browser execute() mechanism kills existing JS
Goto Forum:
  


Current Time: Mon Jul 07 12:40:49 EDT 2025

Powered by FUDForum. Page generated in 0.07408 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top