Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Preventing an SWT_AWT Frame from painting its background (flicker)
Preventing an SWT_AWT Frame from painting its background (flicker) [message #440588] Wed, 04 August 2004 14:22 Go to next message
Eclipse UserFriend
Originally posted by: flobbster.gmail.com

I'm writing an imaging application using Eclipse RCP, but I want to use
Java2D instead of SWT's image facilities. I've tried the Holongate
plugins, but they seem too slow even with the native extensions enabled
(and I've verified that they're enabled), at least when I'm working with
a large editor window (say, around 1024x768).

So, I thought that I could just use SWT_AWT.new_Frame() to create an AWT
Frame directly in my editor and draw into that. This works, except that
the frame flickers madly when I resize it. I can only presume that this
is because the frame is repainting its background before I get a chance
to draw into it.

I can't subclass the frame to override paint()/update(), since it's
created by the SWT_AWT bridge and returned to me, and AWT doesn't
support paint listeners like SWT does, so is there any way to prevent
this frame from painting its background? I tried calling
setIgnoreRepaint(true) on the frame, but that didn't help either.

Thanks,

--
Tony A.
Re: Preventing an SWT_AWT Frame from painting its background (flicker) [message #440594 is a reply to message #440588] Wed, 04 August 2004 15:56 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Try putting a Panel as the first child of the Frame returned by SWT_AWT.
Does the flicker go away?

"Tony A." <flobbster@gmail.com> wrote in message
news:ceqrcl$r8c$1@eclipse.org...
> I'm writing an imaging application using Eclipse RCP, but I want to use
> Java2D instead of SWT's image facilities. I've tried the Holongate
> plugins, but they seem too slow even with the native extensions enabled
> (and I've verified that they're enabled), at least when I'm working with
> a large editor window (say, around 1024x768).
>
> So, I thought that I could just use SWT_AWT.new_Frame() to create an AWT
> Frame directly in my editor and draw into that. This works, except that
> the frame flickers madly when I resize it. I can only presume that this
> is because the frame is repainting its background before I get a chance
> to draw into it.
>
> I can't subclass the frame to override paint()/update(), since it's
> created by the SWT_AWT bridge and returned to me, and AWT doesn't
> support paint listeners like SWT does, so is there any way to prevent
> this frame from painting its background? I tried calling
> setIgnoreRepaint(true) on the frame, but that didn't help either.
>
> Thanks,
>
> --
> Tony A.
Re: Preventing an SWT_AWT Frame from painting its background (flicker) [message #440598 is a reply to message #440594] Wed, 04 August 2004 18:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: flobbster.gmail.com

Steve Northover wrote:
> Try putting a Panel as the first child of the Frame returned by SWT_AWT.
> Does the flicker go away?

No such luck. Here's a simplified version of what I have so far:

* An editor that creates a single child of my class ScrollableAwtCanvas
to fill the entire editor area

* The class ScrollableAwtCanvas extends org.eclipse.swt.widgets.Canvas,
and I create the children in the constructor like this:

----
super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.EMBEDDED |
SWT.NO_BACKGROUND);

frame = SWT_AWT.new_Frame(this);

canvas = new InnerCanvas();
frame.add(canvas);
----

* The InnerCanvas class just extends java.awt.Canvas and overrides the
paint() method so I can draw the image into the window, since I can't
draw directly into the frame without being able to subclass it. I tried
changing it to subclass java.awt.Panel instead, but the flicker is still
there.

It seems like the underlying frame shouldn't be drawing itself when the
InnerCanvas takes up the entire area. Something interesting I noticed
was that if I set the background color of the InnerCanvas object, then
that background color flickers instead of the background of the
frame--even if I override InnerCanvas.update() to just call paint().

Is there something I'm missing here? My AWT knowledge is a bit rusty,
so I'm wondering if there's just a method I'm forgetting to call or
override somewhere.

Thanks,

--
Tony A.
Re: Preventing an SWT_AWT Frame from painting its background (flicker) [message #440667 is a reply to message #440598] Thu, 05 August 2004 14:17 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Silenio says, "Create a Panel as a child of the Frame. Creat a JRootPane as
a child of the Panel and add your widgets to this component. The JRootPane
is double buffered by default."

"Tony A." <flobbster@gmail.com> wrote in message
news:cer8ok$jsk$1@eclipse.org...
> Steve Northover wrote:
> > Try putting a Panel as the first child of the Frame returned by SWT_AWT.
> > Does the flicker go away?
>
> No such luck. Here's a simplified version of what I have so far:
>
> * An editor that creates a single child of my class ScrollableAwtCanvas
> to fill the entire editor area
>
> * The class ScrollableAwtCanvas extends org.eclipse.swt.widgets.Canvas,
> and I create the children in the constructor like this:
>
> ----
> super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.EMBEDDED |
> SWT.NO_BACKGROUND);
>
> frame = SWT_AWT.new_Frame(this);
>
> canvas = new InnerCanvas();
> frame.add(canvas);
> ----
>
> * The InnerCanvas class just extends java.awt.Canvas and overrides the
> paint() method so I can draw the image into the window, since I can't
> draw directly into the frame without being able to subclass it. I tried
> changing it to subclass java.awt.Panel instead, but the flicker is still
> there.
>
> It seems like the underlying frame shouldn't be drawing itself when the
> InnerCanvas takes up the entire area. Something interesting I noticed
> was that if I set the background color of the InnerCanvas object, then
> that background color flickers instead of the background of the
> frame--even if I override InnerCanvas.update() to just call paint().
>
> Is there something I'm missing here? My AWT knowledge is a bit rusty,
> so I'm wondering if there's just a method I'm forgetting to call or
> override somewhere.
>
> Thanks,
>
> --
> Tony A.
Re: Preventing an SWT_AWT Frame from painting its background (flicker) [message #440673 is a reply to message #440667] Thu, 05 August 2004 17:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: flobbster.gmail.com

Steve Northover wrote:
> Silenio says, "Create a Panel as a child of the Frame. Creat a JRootPane as
> a child of the Panel and add your widgets to this component. The JRootPane
> is double buffered by default."

I tried your suggestion, but I'm still getting flicker-thru from the AWT
Frame. It seems like it doesn't matter whether the JRootPane is
buffered or not, for some reason the AWT Frame is still demanding that
its background get painted.

Here's what I have in my constructor now. I decided to try it by just
adding a large button to the JRootPane that takes up the entire client
area, but the Frame's background still flickers when I resize the window:

----
super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.EMBEDDED |
SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE);

frame = SWT_AWT.new_Frame(this);

java.awt.Panel panel = new java.awt.Panel();
panel.setLayout(new java.awt.BorderLayout());
frame.add(panel, java.awt.BorderLayout.CENTER);

JRootPane rootPane = new JRootPane();
panel.add(rootPane);

rootPane.getContentPane().add(new javax.swing.JButton("button"),
java.awt.BorderLayout.CENTER);
----

Could there be anything else causing it? This flickering is pretty much
a show-stopper for my application, if there's no way I can get it stopped.

Thanks,

--
Tony A.
Re: Preventing an SWT_AWT Frame from painting its background (flicker) [message #440701 is a reply to message #440673] Fri, 06 August 2004 14:34 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
It will always flicker when you resize and there's not much we can do about
it. AWT/Swing doesn't respect 'Show window contents while dragging'. When
you resize an AWT/Swing Frame, it issues the resize event when you let go of
the mouse. If it didn't, you'd see the flashing.

"Tony A." <flobbster@gmail.com> wrote in message
news:cetppc$fsc$1@eclipse.org...
> Steve Northover wrote:
> > Silenio says, "Create a Panel as a child of the Frame. Creat a
JRootPane as
> > a child of the Panel and add your widgets to this component. The
JRootPane
> > is double buffered by default."
>
> I tried your suggestion, but I'm still getting flicker-thru from the AWT
> Frame. It seems like it doesn't matter whether the JRootPane is
> buffered or not, for some reason the AWT Frame is still demanding that
> its background get painted.
>
> Here's what I have in my constructor now. I decided to try it by just
> adding a large button to the JRootPane that takes up the entire client
> area, but the Frame's background still flickers when I resize the window:
>
> ----
> super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.EMBEDDED |
> SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE);
>
> frame = SWT_AWT.new_Frame(this);
>
> java.awt.Panel panel = new java.awt.Panel();
> panel.setLayout(new java.awt.BorderLayout());
> frame.add(panel, java.awt.BorderLayout.CENTER);
>
> JRootPane rootPane = new JRootPane();
> panel.add(rootPane);
>
> rootPane.getContentPane().add(new javax.swing.JButton("button"),
> java.awt.BorderLayout.CENTER);
> ----
>
> Could there be anything else causing it? This flickering is pretty much
> a show-stopper for my application, if there's no way I can get it stopped.
>
> Thanks,
>
> --
> Tony A.
Re: Preventing an SWT_AWT Frame from painting its background (flicker) [message #440794 is a reply to message #440701] Fri, 06 August 2004 16:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: flobbster.gmail.com

Steve Northover wrote:
> It will always flicker when you resize and there's not much we can do about
> it. AWT/Swing doesn't respect 'Show window contents while dragging'. When
> you resize an AWT/Swing Frame, it issues the resize event when you let go of
> the mouse. If it didn't, you'd see the flashing.

That's disappointing, but I understand that if it's an underlying AWT
problem, then there's really no way around it. I suppose I'll go back
to using the Holongate Java2D plugins for the time being.

It would be great if a future version of SWT had Java2D interaction
built in--namely, a way to get a Graphics2D object for a component--to
eliminate the performance hit of having to perform an image conversion,
but I know I'm not the first person to ask for something like that, and
I suppose there might be too much AWT baggage to make that feasible.

Do you know if there are any plans for something like this in a future
SWT release?

--
Tony A.
Re: Preventing an SWT_AWT Frame from painting its background (flicker) [message #440973 is a reply to message #440794] Mon, 09 August 2004 15:15 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Not really. SWT runs on platforms where AWT doesn't exist.

"Tony A." <flobbster@gmail.com> wrote in message
news:cf0a3v$5jn$1@eclipse.org...
> Steve Northover wrote:
> > It will always flicker when you resize and there's not much we can do
about
> > it. AWT/Swing doesn't respect 'Show window contents while dragging'.
When
> > you resize an AWT/Swing Frame, it issues the resize event when you let
go of
> > the mouse. If it didn't, you'd see the flashing.
>
> That's disappointing, but I understand that if it's an underlying AWT
> problem, then there's really no way around it. I suppose I'll go back
> to using the Holongate Java2D plugins for the time being.
>
> It would be great if a future version of SWT had Java2D interaction
> built in--namely, a way to get a Graphics2D object for a component--to
> eliminate the performance hit of having to perform an image conversion,
> but I know I'm not the first person to ask for something like that, and
> I suppose there might be too much AWT baggage to make that feasible.
>
> Do you know if there are any plans for something like this in a future
> SWT release?
>
> --
> Tony A.
Previous Topic:SWT pocketpc support
Next Topic:CoolItem tooltip, enable/disable
Goto Forum:
  


Current Time: Fri Apr 19 13:35:28 GMT 2024

Powered by FUDForum. Page generated in 0.02523 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top