[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Multiple Fonts problem

Hi,

thx for the fast help. Indeed my code created a massive memory leak and thus after a few runs the whole Workbench died on me.

Implemting it all with a FontRegistry solved the Problem and the memory usage stays in safe bounds.

Thx angain,
Volker

For all who a curions a snippet of the FontRegistry:

fontRegistry = new FontRegistry(parent.getDisplay());

fontRegistry.put("info-text", new FontData[] { new FontData("Arial", 13, SWT.BOLD) });
fontRegistry.put("team-text", new FontData[] { new FontData("Arial", 11, SWT.BOLD) });



someLabel.setFont(fontRegistry.get("info-text"));

Tom Schindl wrote:
Hi,

Are you sure there's no exception logged in the error-log (you can run with the -consoleLog parameter and see the log in your console then)? Is it possible that the refreshScores-method is called from a thread?

Btw. you are leaking, leaking, leaking fonts. Use a FontRegistry and reuse the fonts instead of always creating new ones.

Tom

V. Spaarmann schrieb:
Hi there,

I have come across a rather strange problem with fonts in my code.

A Label is created in the createPartControl() method of a View and I have written a refresh() method to be executed when the underlying algorithm has finished a step thus altering the text on the Label.

This works just fine but when I try to change the Font of the Label between it's initial creation in createPartControl() and refresh() the whole method just stops at the Label.setFont() method.

Any ideas on what I'm doing wrong?

Thx,
Volker

code snippets:


public void createPartControl(Composite parent) { FillLayout fillLayout = new FillLayout(); fillLayout.type = SWT.VERTICAL; parent.setLayout(fillLayout);

infoLabel = new Label(parent, SWT.CENTER);
infoLabel.setFont(new Font(parent.getDisplay(), "Arial", 18, SWT.BOLD));
infoLabel.setText("Not ready");
}


public void refreshScores()
{
infoLabel.setFont(new Font(mainCanvas.getDisplay(), "Arial", 12, SWT.BOLD)); //in this line it just stalls
infoLabel.setText("another message");
}