SWT No More Handles

If I understand you correctly, you are probably getting the following exception: org.eclipse.swt.SWTError: No more handles You may be creating resources (such as Font, Image or GC objects) that you aren’t correctly disposing. You might want to take a moment to read through the SWT guide on Managing Operating System Resources. To determine if this … Read more

Adding a remove button to a column in a table

Here is sample working version. public class TableEditorTest { /** * @param args */ public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); TableViewer viewer = new TableViewer(shell); viewer.getTable().setHeaderVisible(true); viewer.getTable().setLinesVisible(true); viewer.setContentProvider(new ArrayContentProvider()); TableColumn column = new TableColumn(viewer.getTable(), SWT.NONE); column.setText(“First Name”); column.setWidth(100); TableViewerColumn firstNameCol = new TableViewerColumn(viewer, … Read more

SWT components relayout after visibility set to false

A very simple solution could use GridData::exclude property. For example, Code import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; public class HideLabel { public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new GridLayout(1, false)); shell.setText(“Hide Label”); … Read more

How to hide an SWT composite so that it takes no space?

Here is some code that does what you want. I basically use GridData#exclude in combination with Control#setVisible(boolean) to hide/unhide the Composite: public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText(“StackOverflow”); shell.setLayout(new GridLayout(1, true)); Button hideButton = new Button(shell, SWT.PUSH); hideButton.setText(“Toggle”); final Composite content = new Composite(shell, … Read more

How to set SWT button foreground color?

On Windows, setForeground for Buttons has no effects. As a workaround, add a PaintListener to your Button. On this Listener’s paintControl method, get the generated event’s GC and, with it, re-write the text of your Button using the color you want. You can, in fact, draw anything over your Button.

SWT – OS agnostic way to get monospaced font

I spent a while bashing my head against this one until I realised that obviously eclipse must have access to a monospace font for use in its text fields, console etc. A little digging turned up: Font terminalFont = JFaceResources.getFont(JFaceResources.TEXT_FONT); Which works if all you’re interested in is getting hold of some monospace font. Edit: … Read more