Hi,
Im trying to save a MyJTree class by serializing the class and of
course writing the output to a file.... but every time I try to save
it I get an error:
Exception in thread "AWT-EventQueue-0" java.lang.InternalError:
incorrect component
at javax.swing.plaf.basic.BasicTreeUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
any ideas? code follows....
when the saved button is pressed this happens:
---------------------------------------------
if (e.getActionCommand().equals("mniSave")){ //save the 'file'
try{
ObjectOutputStream out = new ObjectOutputStream(new
FileOutputStream("C:\\test.txt"));
out.writeObject(m_tlTree);
out.flush();
out.close();
}catch (IOException ioe){
System.out.println("Failed to save");
}
-----------------------------------------
my jtree class implements serializable and has this code as writeobject
and readobject...
------------------------------------------------------------------------------------------
// --------- Serializable --------------
//for saving
private void writeObject(java.io.ObjectOutputStream out)
throws IOException {
out.defaultWriteObject();
}
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
}
-----------------------------------------------------------------------------------------------
Roedy Green - 28 Dec 2005 17:26 GMT
>Im trying to save a MyJTree class by serializing the class and of
>course writing the output to a file.... but every time I try to save
>it I get an error:
You do know you can't do that in an unsigned Applet.
See http://mindprod.com/jgloss/applet.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 28 Dec 2005 17:29 GMT
>Exception in thread "AWT-EventQueue-0" java.lang.InternalError:
>incorrect component
> at javax.swing.plaf.basic.BasicTreeUI.paint(Unknown Source)
> at javax.swing.plaf.ComponentUI.update(Unknown Source)
> at javax.swing.JComponent.paintComponent(Unknown Source)
Try putting in some debug code. Your problem may have nothing to do
with serializing. Try System.out.println("here");
just before you start to serialize.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Thomas Hawtin - 28 Dec 2005 19:00 GMT
> Im trying to save a MyJTree class by serializing the class and of
> course writing the output to a file.... but every time I try to save
[quoted text clipped - 5 lines]
> at javax.swing.plaf.ComponentUI.update(Unknown Source)
> at javax.swing.JComponent.paintComponent(Unknown Source)
Swing components uninstall their UI delegate when serialising. Possibly
it is a problem relating to that (I don't think it is tolerant of
exceptions, for instance).
I've tried to reproduce your problem with no lock. My code is below.
Does it work for you? Can you make it not work (in the appropriate style)?
Tom Hawtin
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyTree extends JTree {
private void writeObject(
ObjectOutputStream out
) throws IOException {
out.defaultWriteObject();
}
private void readObject(
ObjectInputStream in
) throws IOException, ClassNotFoundException {
in.defaultReadObject();
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("SerialTree");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLayout(new BorderLayout());
final JTree tree = new MyTree();
frame.add(tree);
JButton save = new JButton("Save");
save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
try {
OutputStream fileOut =
new FileOutputStream("test.ser");
try {
ObjectOutputStream objectOut =
new ObjectOutputStream(
fileOut
);
objectOut.writeObject(tree);
objectOut.flush();
} finally {
fileOut.close();
}
} catch (IOException exc) {
exc.printStackTrace();
}
}
});
frame.add(save, BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
}
});
}
}

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Andrew Thompson - 29 Dec 2005 00:41 GMT
> Sub: saving a jtree...
Use less JPaper!
( sorry, I just couldn't resist that )

Signature
Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew