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.
# 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;
}
}
}
/*************************************************************************************************/