#1084 Font. width and "No GfxEnv is active" error

tcolar Sat 24 Apr 2010

I'm trying to make my own UI component I'm using font.width to calculate it's size but unless a windows is already open I get this error:

sys::Err: No GfxEnv is active

gfx::GfxEnv.cur (GfxEnv.fan:30)
gfx::GfxEnv.cur (GfxEnv.fan)
gfx::Font.width (Font.fan:228)
netColarUI::RichLabel.prefSize (RichLabel.fan:35)

.....

It works if I open a window first .... but i'd like to create the component before calling window.open loop rather than have to create it through an event.

What's the deal withat, any ideas ?

andy Sat 24 Apr 2010

That initial window.open call is whats initializing the current GfxEnv to SWT, which provides the implementation for things such as Font.width. Looks like you can workaround that by calling Desktop.bounds which will bind the GfxEnv as well.

tcolar Tue 27 Apr 2010

Thanks that worked.

Also in RichTextPeer.java, there is:

// this is a hack, but seems to be the only way to set
// the margins hidden away as private fields in StyledText
setField(t, "leftMargin",   8);
setField(t, "topMargin",    0);
setField(t, "rightMargin",  8);
setField(t, "bottomMargin", 8);

Any reason why that stuff(margins) is hidden/hard-coded in the Java rather than configurable ?

At first I thought it might make JavaScript compatibility easier .. but it seem Richtext is not even implemented in Javascript anyway (empty file)

Login or Signup to reply.