Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 18:39 Go to next message
Jan Krakora is currently offline Jan KrakoraFriend
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

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 18:40]

Report message to a moderator

Re: Drawing a border around a Combo [message #641105 is a reply to message #640332] Wed, 24 November 2010 09:34 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Nobody knows??
Re: Drawing a border around a Combo [message #641218 is a reply to message #641105] Wed, 24 November 2010 14:38 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
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??
Previous Topic:Long cells in table/tree - truncate from left?
Next Topic:Browser execute() mechanism kills existing JS
Goto Forum:
  


Current Time: Mon Dec 11 06:03:22 GMT 2017

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

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