TextArea Problem since Java 1.4, Screen flickers in WinXP

Today i checked the sources of Java 1.5 and detected one big chance since Java 1.1, the TextArea is no longer created as a simple Class "EDIT" ( in Windows native call CreateWindow ), 1.5 uses RichEdit.

We a Application which was running with 1.1 without problems, now we moved to 1.5 and have big problems.

We have a Frame with a TextArea and some Buttons, every time when i call repaint on the Frame, my Desktop Icons vanish and reload they bitmap from the binary ( means Icon Cache is flushed ), can anybody confirm this or help me to get around this bug ?

Otherwise i file a Bugreport.

The main reason for us to stay with 1.1 were this bugs in the releases 1.2, 1.3,1.4,1.5,1.6 which are unusable in the production.

How did this get thru the QA ? And please do not blame Microsoft !

P.S: I searched google , java forums, but i didn't find any explaination for this behavior.

[922 byte] By [MGodehardta] at [2007-11-26 16:48:55]
# 1
Perhaps the problem is in your code and not in the Java implementation. Why are you calling repaint on the Frame?
Jasprea at 2007-7-8 23:16:28 > top of Java-index,Desktop,Core GUI APIs...
# 2

repaint() updates my Frame, paint() is called and i can draw the current state of some variables like Counter, Text, etc...

Problem is the RichEdit Control, dunno why but its causing this problem. My riched20.dll version is 5.30.23.1221, Rich Text Edit Control, v3.0

This Problem also occurs when i start the JMStudio and installed Java 1.5 on my machine, JMFStudio will use Java 1.5.

Open JMStudio, go to File-->Preferences, then JMF Registry Editor will pop up and my icons on the desktop loose they bitmap ( its reloaded from the binary), its not my code, its Java which is causing this :-(

If anybody can confirm this, i will file a bug until it makes it way to the news

MGodehardta at 2007-7-8 23:16:28 > top of Java-index,Desktop,Core GUI APIs...
# 3

Since the old code was in 1.1 I definitely think you need to give Jaspre's reply more weight.There have been so many changes to the language. 1.5 might just be making a bug you have in your code more visible.

Either way you might just want to rewrite some of the code to utilize some of the improvements in Java.

zadoka at 2007-7-8 23:16:28 > top of Java-index,Desktop,Core GUI APIs...
# 4

Please do not file a bug unless you can prove its a bug. Please post some code (a [url http://homepage1.nifty.com/algafield/sscce.html]SSCCE[/url]) that demonstrates your problem so we can all see this bug for ourselves. If you can't reproduce the problem with a small example, then it's more likely the problem is in your code.

Jasprea at 2007-7-8 23:16:28 > top of Java-index,Desktop,Core GUI APIs...
# 5

And here the code comes which is causing this :-)

compile with normal java1.5 compiler no special settings needed and run with java 1.5 no special settings needed.

This code causes flickering of desktop, because TextArea is added in Constructor of Class. Open a Command prompt and start the class a dialog will pop up and all icons on desktop will flicker :-)

import java.lang.*;

import java.net.*;

import java.io.*;

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import java.text.*;

/**************************************************************************************************

*

*************************************************************************************************/

public class Test extends Frame

{

public static TextAreaitsEdit;

public static Frame itsFrame;

/**********************************************************************************************

*

*********************************************************************************************/

private Test()

{

enableEvents(AWTEvent.WINDOW_EVENT_MASK);

setTitle("Test");

setLayout(null);

setResizable(false);

setBackground(SystemColor.control);

setLocation(5, 5);

// edit field

itsEdit = new TextArea("", 20, 6, TextArea.SCROLLBARS_BOTH);

itsEdit.setBackground(SystemColor.window);

itsEdit.setVisible(false);

add(itsEdit);

show();

}

/**********************************************************************************************

*

*********************************************************************************************/

static public void mywait(long millis)

{

try

{

Thread.sleep(millis);

}

catch ( Exception ex )

{

}

}

/**********************************************************************************************

*

*********************************************************************************************/

static public void appendStatusText(String aText)

{

itsEdit.append(aText);

itsFrame.repaint();

}

/**********************************************************************************************

* STARTUP

*********************************************************************************************/

static public void main(String[] args)

{

try

{

itsFrame = new Test();

Test.mywait(1000);

while ( !itsFrame.isVisible() )

{

Test.mywait(100);

}

appendStatusText("Bitte warten ...");

for (int idx=0; idx<10000; idx++)

{

appendStatusText("Loop #" + idx + "\n");

Test.mywait(100);

itsEdit.setVisible(true);

}

}

catch ( Exception ex )

{

ex.printStackTrace();

}

// cleanup and exit

System.out.flush();

System.exit(0);

}

/**********************************************************************************************

*

*********************************************************************************************/

public void paint(Graphics g)

{

g.setColor(SystemColor.control);

g.fillRect(0 , 0, getBounds().width, getBounds().height);

super.paint(g);

}

/**********************************************************************************************

*

*********************************************************************************************/

private void updateSize()

{

Insets insets = getInsets();

int logoHeight = 0;

setSize(400, 300);

// edit field

itsEdit.setBounds(insets.left + 5, insets.top + 5, 350, 106);

itsEdit.setEditable(false);

itsEdit.setVisible(true);

}

/**********************************************************************************************

* handle Window Events

*********************************************************************************************/

protected void processWindowEvent(WindowEvent e)

{

if ( e.getID() == WindowEvent.WINDOW_OPENED )

{

updateSize();

///add(itsEdit);

}

else if ( e.getID() == WindowEvent.WINDOW_CLOSING )

{

if ( null != itsFrame )

{

itsFrame.dispose();

}

}

else if ( e.getID() == WindowEvent.WINDOW_CLOSED )

{

itsFrame = null;

}

}

}

/*************************************************************************************************/

This code adds the TextArea itsEdit in processWindowEvent WINDOW_OPENED event, no flickering at all.

import java.lang.*;

import java.net.*;

import java.io.*;

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import java.text.*;

/**************************************************************************************************

*

*************************************************************************************************/

public class Test extends Frame

{

public static TextAreaitsEdit;

public static Frame itsFrame;

/**********************************************************************************************

*

*********************************************************************************************/

private Test()

{

enableEvents(AWTEvent.WINDOW_EVENT_MASK);

setTitle("Test");

setLayout(null);

setResizable(false);

setBackground(SystemColor.control);

setLocation(5, 5);

// edit field

itsEdit = new TextArea("", 20, 6, TextArea.SCROLLBARS_BOTH);

itsEdit.setBackground(SystemColor.window);

itsEdit.setVisible(false);

////add(itsEdit);

show();

}

/**********************************************************************************************

*

*********************************************************************************************/

static public void mywait(long millis)

{

try

{

Thread.sleep(millis);

}

catch ( Exception ex )

{

}

}

/**********************************************************************************************

*

*********************************************************************************************/

static public void appendStatusText(String aText)

{

itsEdit.append(aText);

itsFrame.repaint();

}

/**********************************************************************************************

* STARTUP

*********************************************************************************************/

static public void main(String[] args)

{

try

{

itsFrame = new Test();

Test.mywait(1000);

while ( !itsFrame.isVisible() )

{

Test.mywait(100);

}

appendStatusText("Bitte warten ...");

for (int idx=0; idx<10000; idx++)

{

appendStatusText("Loop #" + idx + "\n");

Test.mywait(100);

itsEdit.setVisible(true);

}

}

catch ( Exception ex )

{

ex.printStackTrace();

}

// cleanup and exit

System.out.flush();

System.exit(0);

}

/**********************************************************************************************

*

*********************************************************************************************/

public void paint(Graphics g)

{

g.setColor(SystemColor.control);

g.fillRect(0 , 0, getBounds().width, getBounds().height);

super.paint(g);

}

/**********************************************************************************************

*

*********************************************************************************************/

private void updateSize()

{

Insets insets = getInsets();

int logoHeight = 0;

setSize(400, 300);

// edit field

itsEdit.setBounds(insets.left + 5, insets.top + 5, 350, 106);

itsEdit.setEditable(false);

itsEdit.setVisible(true);

}

/**********************************************************************************************

* handle Window Events

*********************************************************************************************/

protected void processWindowEvent(WindowEvent e)

{

if ( e.getID() == WindowEvent.WINDOW_OPENED )

{

updateSize();

add(itsEdit);

}

else if ( e.getID() == WindowEvent.WINDOW_CLOSING )

{

if ( null != itsFrame )

{

itsFrame.dispose();

}

}

else if ( e.getID() == WindowEvent.WINDOW_CLOSED )

{

itsFrame = null;

}

}

}

/*************************************************************************************************/

MGodehardta at 2007-7-8 23:16:28 > top of Java-index,Desktop,Core GUI APIs...
# 6
No replies since last update, if anybody can confirm this i would be happy.In 2 weeks i will file this as a bug to SUN
MGodehardta at 2007-7-8 23:16:28 > top of Java-index,Desktop,Core GUI APIs...
# 7

I have a much simpler demonstration of TextArea severely impacting Windows XP. And I when I say "severe", I mean it affects _other_ applications, non-java ones. The _ENTIRE_ screen flickers, all Windows widgets, every one, with the following code on my Windows XP SP2 machine under both JRE 1.5 and JRE 1.6. If I alt-tab the JFrame into the background behind a full-screen window of, say, Firefox, then my entire screen stops flickering, but the JFrame flickers through, as if it were momentarily in-focus and then behind Firefox again. The flicker is exactly timed with x.append(..) - that is, the action of appending to a TextBox causes these disastrous results. If you change the sleep cycle from 1000ms to something else, you'll notice the flicker frequency (of the ALL WinXP widgets, even those belonging to other processes) matches.

class Buggy

{

public static void main(String[] args) throws Exception

{

JFrame frame = new JFrame("Socket Test");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(370, 400);

final TextArea x = new TextArea();

x.setEditable(false);

JTabbedPane bug = new JTabbedPane();

bug.addTab("Buggy", x);

frame.add(bug);

frame.validate();

frame.setVisible(true);

new Thread(new Runnable()

{

public void run() {

try {

for(int i = 0; true; i++) {

x.append("Message["+i+"]: foobar\n");

Thread.sleep(1000);

}

} catch(InterruptedException e) {

e.printStackTrace();

}

}

}).start();

}

}

synackfina at 2007-7-8 23:16:28 > top of Java-index,Desktop,Core GUI APIs...
# 8
Ignore the label "Socket Test", I was copy+pasting from an application with that title. There's nothing involving Sockets in the code.
synackfina at 2007-7-8 23:16:28 > top of Java-index,Desktop,Core GUI APIs...
# 9
Nevermind, the XP flickering problem seems to be a weird sideaffect of running an IntelliJ process on the same machine (not necessarily as the parent process). I don't notice any system-wide flickering issues when running the java app without an IntelliJ process around.
synackfina at 2007-7-8 23:16:28 > top of Java-index,Desktop,Core GUI APIs...
# 10

Okay... I spoke too soon. There _IS_ a partial system-wide flicker (no other java processes or IntelliJ were running to rule out sideaffect issues). All that's running is WinXP and my Java app. The desktop icons all flicker along with my java app (in sync with the x.append(..) invocations) . Other modal windows (explorer, etc.) are unaffected and do not flicker.

synackfina at 2007-7-8 23:16:28 > top of Java-index,Desktop,Core GUI APIs...
# 11

In addition to the desktop, gaim apparently also flickers with the x.append(..), as does intellij as previously stated. This issue occurs only when the TextArea is added to a JTabbedPane (and I'm assuming other lightweight panels have bad interaction with TextArea as well). I do not notice any system-wide flickering issues when TextArea is directly added to JFrame.

synackfina at 2007-7-8 23:16:28 > top of Java-index,Desktop,Core GUI APIs...