Skip to content

Instantly share code, notes, and snippets.

@jonahgraham
Last active November 26, 2025 21:01
Show Gist options
  • Select an option

  • Save jonahgraham/ac9ec93372e703f909ea16b31c9b0fae to your computer and use it in GitHub Desktop.

Select an option

Save jonahgraham/ac9ec93372e703f909ea16b31c9b0fae to your computer and use it in GitHub Desktop.
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class SnippetDrawOverButton {
public static void main(String [] args) {
var display = new Display();
var shell = new Shell(display);
FillLayout layout = new FillLayout();
layout.marginHeight = 5;
layout.marginWidth = 5;
shell.setLayout(layout);
Group group = new Group(shell, SWT.NONE);
group.setText("This is a group here");
layout = new FillLayout();
layout.marginHeight = 5;
layout.marginWidth = 5;
group.setLayout(layout);
Button button = new Button(group, SWT.PUSH);
button.setText("SnippetDrawOverButton");
Font initialFont = button.getFont();
FontData[] fontData = initialFont.getFontData();
for (FontData element : fontData) {
element.setHeight(24);
}
Font newFont = new Font(display, fontData);
button.setFont(newFont);
group.addPaintListener(event -> {
System.out.print(" **********PAINTING************** ");
Point rect = group.getSize();
event.gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
event.gc.setLineWidth(5);
event.gc.drawOval(-10, -10, rect.x - 2, rect.y - 2);
});
shell.pack();
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment