示例#1
0
 /** Sets or clears the caret in the "Example" widget. */
 void setCaret() {
   Caret oldCaret = canvas.getCaret();
   if (caretButton.getSelection()) {
     Caret newCaret = new Caret(canvas, SWT.NONE);
     Font font = canvas.getFont();
     newCaret.setFont(font);
     GC gc = new GC(canvas);
     gc.setFont(font);
     newCaret.setBounds(1, 1, 1, gc.getFontMetrics().getHeight());
     gc.dispose();
     canvas.setCaret(newCaret);
     canvas.setFocus();
   } else {
     canvas.setCaret(null);
   }
   if (oldCaret != null) oldCaret.dispose();
 }
 /**
  * Sets the receiver's size and location to the rectangular area specified by the argument. The
  * <code>x</code> and <code>y</code> fields of the rectangle are relative to the receiver's parent
  * (or its display if its parent is null).
  *
  * @param rect the new bounds for the receiver
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void setBounds(Rectangle rect) {
   if (rect == null) error(SWT.ERROR_NULL_ARGUMENT);
   setBounds(rect.x, rect.y, rect.width, rect.height);
 }