-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.6
-
x86
-
windows_95
Name: mf23781 Date: 08/20/98
* Test case:
/*
* (C) Copyright IBM Corp. 1997-1998 All rights reserved.
*
* US Government Users Restricted Rights Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
//package com.ibm.xml.sample;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Color;
import java.util.Enumeration;
import java.util.Hashtable;
import java.awt.event.*;
import com.sun.java.swing.event.MenuListener;
import com.sun.java.swing.event.MenuEvent;
import com.sun.java.swing.JFrame;
import com.sun.java.swing.JMenu;
import com.sun.java.swing.JMenuBar;
import com.sun.java.swing.JMenuItem;
import com.sun.java.swing.JScrollPane;
import com.sun.java.swing.JTree;
import com.sun.java.swing.UIManager;
import com.sun.java.swing.tree.*;
import com.sun.java.swing.event.TreeSelectionListener;
import com.sun.java.swing.event.TreeSelectionEvent;
import com.sun.java.swing.UnsupportedLookAndFeelException;
import com.sun.java.swing.JTextField;
import com.sun.java.swing.JTextArea;
import com.sun.java.swing.JEditorPane;
import com.sun.java.swing.JPanel;
import java.util.*;
import java.io.*;
import java.awt.GridLayout;
/**
*
* @version 19980603
* @author TAMURA Kent <###@###.###>
* @author PFEIFFER Ralf <###@###.###>
*/
public class JTextAreaBug extends JFrame implements ActionListener, TextListener {
public static final boolean DEBUG = true;
public static void main(String[] argv) {
// default is hamlet.xml
String fname = "hamlet.xml";
if (1 != argv.length) {
new JTextAreaBug("JTextAreaBug", fname).show();
} else {
fname = argv[0];
try {
new JTextAreaBug("JTextAreaBug", fname).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
String fname;
UIManager.LookAndFeelInfo[] m_alooks = null;
JScrollPane m_scrollpane, m_textScrollPane;
JTextArea m_textArea;
//JEditorPane m_textArea;
Vector textLine = new Vector();
public synchronized void writeXMLFile(String filename, JTextArea textArea) {
try {
// create stream
FileOutputStream fos = new FileOutputStream(filename);
// create print writer
PrintWriter out = new PrintWriter(fos);
out.print(textArea.getText());
fos.close();
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
/** read the xml file and put it in a JTextArea */
public synchronized JTextArea readXMLFile(String filename) {
if (DEBUG) System.out.println("START readXMLFile"+filename);
File file = new File(filename);
FileInputStream fis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(file);
dis = new DataInputStream(fis);
} catch (FileNotFoundException fnf) {
System.err.println("ERROR: XML4J.readXMLFile: "+fnf);
return null;
}
String line;
int i = 0;
int len = 0;
try{
readline: while ((line = dis.readLine()) != null) {
m_textArea.append(line+"\n");
textLine.addElement(new Integer(len));
len += line.length()+"\n".length();
//System.out.println("readXMLFile.line="+line);
}
} catch (IOException io) {
System.err.println(io);
return m_textArea;
}
if (DEBUG) System.out.println("END readXMLFile"+filename);
return m_textArea;
}
void createUIAndRelayout(String filename) {
Container cont = getContentPane();
cont.remove(m_UI);
textLine = new Vector();
cont.add(createUI());
//= new JScrollPane(m_tree = new JTree(getRoot(fname))));
//***to_do: remove this hack when we know how to
//*** get the damn update to show the proper way!!!
Dimension size = getSize();
resize(size.width, size.height+1);
resize(size.width, size.height-1);
/***
while (cont != null) {
cont.invalidate();
cont.repaint();
cont = cont.getParent();
}
invalidate();
repaint();
/***/
}
public void textValueChanged(TextEvent e) {
try {
fname = ((JTextField)e.getSource()).getText();
createUIAndRelayout(fname);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void actionPerformed(java.awt.event.ActionEvent e) {
if (DEBUG) System.err.println("ACTION: "+e.getActionCommand()+", "+e.paramString());
if (e.getActionCommand().equals("Quit")) {
System.exit(0);
}
else if (e.getActionCommand().equals("Open")) {
}
else if (e.getActionCommand().equals("Save")) {
writeXMLFile(fname, m_textArea);
}
}
String reloadString = "Reload current XML file";
public void setLookAndFeel(String feel) {
try {
UIManager.setLookAndFeel(feel);
m_scrollpane.updateUI();
m_textArea.updateUI();
m_textScrollPane.updateUI();
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
} catch (InstantiationException ie) {
ie.printStackTrace();
} catch (IllegalAccessException iae) {
iae.printStackTrace();
} catch (UnsupportedLookAndFeelException ulafe) {
ulafe.printStackTrace();
}
return;
}
public JTextAreaBug(String title, String filename) {
super(title);
fname = filename;
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
//m_alooks = UIManager.getInstalledLookAndFeels();
/***
// comment out Look&Feel menu for Wed June 17 demo...
JMenu jm = new JMenu("Look&Feel");
for (int i = 0; i < m_alooks.length; i ++) {
JMenuItem mi = new JMenuItem(m_alooks[i].getName());
mi.addActionListener(this);
jm.add(mi);
}
/***/
JMenuBar jmb = new JMenuBar();
JMenu fileMenu = new JMenu("File");
//fileMenu.setFont(new Font("Helvetica", Font.PLAIN, 14));
JMenuItem item;
item = new JMenuItem("Open");
fileMenu.add(item);
item.addActionListener(this);
item = new JMenuItem("Quit");
fileMenu.add(item);
item.addActionListener(this);
JMenu shortcutMenu = new JMenu("Shortcuts");
item = new JMenuItem(reloadString);
shortcutMenu.add(item);
item.addActionListener(this);
jmb.add(fileMenu);
// comment out Look&Feel menu for Wed June 17 demo...
//jmb.add(jm);
jmb.add(shortcutMenu);
setJMenuBar(jmb);
getContentPane().add(createUI());
//setLookAndFeel(m_alooks[m_alooks.length-1].getClassName());
setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
setSize(790, 590);
}
JPanel m_UI, m_message;
JPanel createUI() {
if (DEBUG) System.out.println("START createUI:");
m_UI = new JPanel();
m_UI.setLayout(new BorderLayout());
m_scrollpane = new JScrollPane(new JPanel());
m_message = new JPanel();
m_message.setFont(new Font("Helvetica", Font.PLAIN, 18));
m_textArea = new JTextArea(2000,100);
m_textArea.setFont(new Font("Courier", Font.PLAIN, 18));
m_textArea = readXMLFile(fname);
m_textArea.setBackground(Color.white);
m_textArea.setForeground(Color.black);
m_textArea.setSelectedTextColor(Color.black);
m_textArea.setSelectionColor(Color.red);
m_textArea.setOpaque(true);
m_textArea.setEditable(true);
m_textArea.setEnabled(true);
m_textScrollPane = new JScrollPane(m_textArea);
m_textScrollPane.setBackground(Color.white);
m_textScrollPane.setForeground(Color.black);
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new GridLayout(1,2));
centerPanel.add(m_scrollpane);
centerPanel.add(m_textScrollPane);
m_UI.add("Center", centerPanel);
m_UI.add("South", m_message);
if (DEBUG) System.out.println("END createUI:");
return m_UI;
}
}
*Symptoms:
Create a:
JTextArea foo = new JTextArea(2000,100);
within a JPanel inside an application with some other Swing
component.
Now click inside the JTextArea with the mouse. Other parts of your
application
are inexplicably bitmapped into the JTextArea, where your mouse has
clicked.
Scrolling the JTextArea will repaint it and temporarily turn in back to
normal.
But click inside the JTextArea again and you get the same bizarre
behaviour.
This only happens on Win95, and 98, not on WinNT.
======================================================================
- duplicates
-
JDK-4138673 Graphics coordinate overflow with sizes larger than Short.MAX_VALUE
-
- Closed
-