JTextPane

Reply

Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 7
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

JTextPane

 
0
  #1
Feb 10th, 2005
Hi everyone,

I am currently trying to serialize parts of a jtextpane using the java ObjectOutputStream to write it to disk and when i am reading the object back i am using the java ObjectInputStream.

When i read the api about the streams here is what they say

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.
After reading this i decided to serialize my jtextpane objects using the above
xml format but could not get it to work

I am providing a ruunable example so you guys can compile the source code and see what i mean

  1.  
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.io.*;
  5. import java.util.*;
  6. import java.beans.*;
  7. import javax.swing.*;
  8. import javax.swing.event.*;
  9. import javax.swing.text.*;
  10. import javax.swing.text.rtf.*;
  11.  
  12. public class XMLEcoderDecoder implements ActionListener, ItemListener
  13. {
  14.  
  15. JFrame mainFrame = new JFrame("Frame");
  16.  
  17. JLabel labelerror = new JLabel(" ", SwingConstants.RIGHT);
  18. JButton bLoad = new JButton("Load");
  19. JButton bSaveAs = new JButton("Save as");
  20. JButton bSave = new JButton("Save");
  21. JButton bInsertPic = new JButton("Insert picture");
  22. JButton bBackgroundColor = new JButton("Set background color");
  23.  
  24. JFileChooser selectedFile = new JFileChooser();
  25. JFileChooser insertIconFile = new JFileChooser();
  26.  
  27. JColorChooser backgroundChooser = new JColorChooser();
  28.  
  29. Color backgroundColor;
  30.  
  31. JComboBox fontFamily;
  32. JComboBox fontSize = new JComboBox();
  33.  
  34. JTextPane mainTextPane = new JTextPane();
  35.  
  36. SimpleAttributeSet sas = new SimpleAttributeSet();
  37.  
  38. StyleContext sc = new StyleContext();
  39.  
  40. MutableAttributeSet mas;
  41.  
  42. DefaultStyledDocument dse = new DefaultStyledDocument(sc);
  43.  
  44. JScrollPane mainScrollPane = new JScrollPane(mainTextPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
  45. ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  46.  
  47. RTFEditorKit rtfkit = new RTFEditorKit();
  48.  
  49. Dimension Size1 = new Dimension();
  50.  
  51. String SF = "";
  52.  
  53. public void initialize ()
  54. {
  55. Container pane = mainFrame.getContentPane();
  56. pane.setLayout(new FlowLayout());
  57. mainFrame.setSize(250,300);
  58. mainFrame.setLocation(300,300);
  59. mainFrame.setBackground(Color.lightGray);
  60. //The below command line is the JTextPane using the rtf editor kit
  61. //for any rtf editing
  62.  
  63. mainTextPane.setEditorKit(rtfkit);
  64. //The below command line sets the document that the JTextPane will be
  65. //be referencing to
  66.  
  67. mainTextPane.setDocument(dse);
  68. Size1.width = 500;
  69. Size1.height = 300;
  70. mainScrollPane.setPreferredSize(Size1);
  71. pane.add(mainScrollPane);
  72. pane.add(bLoad);
  73. pane.add(bSaveAs);
  74. pane.add(bSave);
  75. pane.add(bInsertPic);
  76. pane.add(bBackgroundColor);
  77.  
  78. combofontfamilyinitialize();
  79. pane.add(fontFamily);
  80. combofontsizeinitialize();
  81. pane.add(fontSize);
  82. pane.add(labelerror);
  83.  
  84. mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  85. bLoad.addActionListener(this);
  86. bSaveAs.addActionListener(this);
  87. bSave.addActionListener(this);
  88. bInsertPic.addActionListener(this);
  89. bBackgroundColor.addActionListener(this);
  90.  
  91. fontFamily.addItemListener(this);
  92. fontSize.addItemListener(this);
  93. mainFrame.pack();
  94. mainFrame.setVisible(true);
  95. }
  96.  
  97. public void combofontfamilyinitialize ()
  98. {
  99. //This function fills the combo box with the system available font families
  100.  
  101. GraphicsEnvironment ge1 = GraphicsEnvironment.getLocalGraphicsEnvironment();
  102. String[] k = ge1.getAvailableFontFamilyNames();
  103. fontFamily= new JComboBox(k);
  104. }
  105.  
  106. public void combofontsizeinitialize ()
  107. {
  108. //This function fills the combo box with font sizes
  109.  
  110. fontSize.addItem("8");
  111. fontSize.addItem("9");
  112. fontSize.addItem("10");
  113. fontSize.addItem("11");
  114. fontSize.addItem("12");
  115. fontSize.addItem("14");
  116. fontSize.addItem("16");
  117. fontSize.addItem("18");
  118. fontSize.addItem("20");
  119. fontSize.addItem("22");
  120. fontSize.addItem("24");
  121. fontSize.addItem("26");
  122. fontSize.addItem("28");
  123. fontSize.addItem("36");
  124. fontSize.addItem("48");
  125. fontSize.addItem("72");
  126. }
  127.  
  128. public void setAttributeSet(AttributeSet attr)
  129. {
  130.  
  131. //This function only set the specified font set by the
  132. //attr variable to the text selected by the mouse
  133.  
  134. int xStart, xFinish, k;
  135.  
  136. xStart = mainTextPane.getSelectionStart();
  137. xFinish = mainTextPane.getSelectionEnd();
  138. k = xFinish - xStart;
  139.  
  140. if(xStart != xFinish)
  141. {
  142. dse.setCharacterAttributes(xStart, k, attr, false);
  143. }
  144.  
  145. else if(xStart == xFinish)
  146. {
  147. //The below two command line updates the JTextPane according to what
  148. //font that is being selected at a particular moment
  149.  
  150. mas = rtfkit.getInputAttributes();
  151. mas.addAttributes(attr);
  152. }
  153. //The below command line sets the focus to the JTextPane
  154.  
  155. mainTextPane.grabFocus();
  156. }
  157.  
  158. public void open ()
  159. {
  160.  
  161. if(selectedFile.showOpenDialog(mainFrame) != JFileChooser.APPROVE_OPTION)
  162. {
  163. return;
  164. }
  165.  
  166. try
  167. {
  168. File file1 = selectedFile.getSelectedFile();
  169. SF = file1.toString();
  170. FileInputStream fStream = new FileInputStream(SF);
  171. XMLDecoder stream = new XMLDecoder(fStream);
  172.  
  173. Object obj;
  174. int i = 0;
  175.  
  176. //The below for loop reads in all the two objects required
  177. //for the initialization of the objects in the program
  178.  
  179. for(i=0;i<2;i++)
  180. {
  181. //The below command line reads the first object in the file
  182.  
  183. obj = stream.readObject();
  184.  
  185. //The below command line initializes the first object in the file
  186. //coresponding to the objects in the program
  187.  
  188. loadinitialize(obj);
  189. }
  190.  
  191. stream.close();
  192. fStream.close();
  193. }
  194.  
  195. catch (Exception e)
  196. {
  197. labelerror.setText("A document reading error has occured");
  198. }
  199.  
  200. }
  201.  
  202. public void loadinitialize(Object Object1)
  203. {
  204. //This function initilizes all the objects in the program according
  205. //to the loading of a new file
  206.  
  207. if(Object1 instanceof DefaultStyledDocument)
  208. {
  209. //The document must be first read into the DefaultStyledDocument
  210. //before any document rendering can be done to it
  211.  
  212. dse = ((DefaultStyledDocument)Object1);
  213. mainTextPane.setDocument(dse);
  214. }
  215.  
  216. else if(Object1 instanceof Color)
  217. {
  218. //The below command line loads the color as an object
  219. //using the user specified file name and sets the color
  220. //to the current JTextPane
  221.  
  222. mainTextPane.setBackground((Color)Object1);
  223. }
  224.  
  225. }
  226.  
  227. public void saveas ()
  228. {
  229.  
  230. if(selectedFile.showSaveDialog(mainFrame) != JFileChooser.APPROVE_OPTION)
  231. {
  232. return;
  233. }
  234.  
  235. try
  236. {
  237. File file2 = selectedFile.getSelectedFile();
  238. SF = (file2.toString() + ".xml");
  239. FileOutputStream fStream = new FileOutputStream(SF);
  240. XMLEncoder stream = new XMLEncoder(fStream);
  241. stream.writeObject(mainTextPane.getDocument());
  242. stream.writeObject(mainTextPane.getBackground());
  243. stream.flush();
  244. stream.close();
  245. fStream.close();
  246. }
  247.  
  248. catch (Exception e)
  249. {
  250. labelerror.setText("A document writing error has occured");
  251. }
  252.  
  253. }
  254.  
  255. public void save ()
  256. {
  257.  
  258. try
  259. {
  260. String str1 = SF;
  261.  
  262. if(str1.equals(""))
  263. {
  264. saveas();
  265. return;
  266. }
  267.  
  268. FileOutputStream fStream = new FileOutputStream(str1);
  269. XMLEncoder stream = new XMLEncoder(fStream);
  270. stream.writeObject(mainTextPane.getDocument());
  271. stream.writeObject(mainTextPane.getBackground());
  272. stream.flush();
  273. stream.close();
  274. fStream.close();
  275. }
  276.  
  277. catch (Exception e)
  278. {
  279. labelerror.setText("A document writing error has occured");
  280. }
  281.  
  282. }
  283.  
  284. public void actionPerformed(ActionEvent event)
  285. {
  286. JComponent b = (JComponent)event.getSource();
  287. String str3 = null;
  288.  
  289. if(b == bLoad)
  290. {
  291. open();
  292. }
  293.  
  294. else if(b == bSaveAs)
  295. {
  296. saveas();
  297. }
  298.  
  299. else if(b == bSave)
  300. {
  301. save();
  302. }
  303.  
  304. else if(b == bInsertPic)
  305. {
  306.  
  307. insertIconFile.setDialogType(JFileChooser.OPEN_DIALOG);
  308. insertIconFile.setDialogTitle("Select a picture to insert into document");
  309.  
  310. if(insertIconFile.showDialog(mainFrame,"Insert") != JFileChooser.APPROVE_OPTION)
  311. {
  312. return;
  313. }
  314.  
  315. File g = insertIconFile.getSelectedFile();
  316. ImageIcon image1 = new ImageIcon(g.toString());
  317. mainTextPane.insertIcon(image1);
  318. mainTextPane.grabFocus();
  319. }
  320.  
  321. else if(b == bBackgroundColor)
  322. {
  323.  
  324. backgroundColor = backgroundChooser.showDialog(mainFrame, "Color Chooser", Color.white);
  325.  
  326. if(backgroundColor != null)
  327. {
  328. mainTextPane.setBackground(backgroundColor);
  329. }
  330.  
  331. }
  332.  
  333. }
  334.  
  335. public void itemStateChanged(ItemEvent event)
  336. {
  337. JComponent c = (JComponent)event.getSource();
  338. boolean d;
  339.  
  340. if(c == fontFamily)
  341. {
  342.  
  343. String j = (String)fontFamily.getSelectedItem();
  344. StyleConstants.setFontFamily(sas, j);
  345. setAttributeSet(sas);
  346. }
  347.  
  348. else if(c == fontSize)
  349. {
  350.  
  351. String h = (String)fontSize.getSelectedItem();
  352. int r = Integer.parseInt(h);
  353. StyleConstants.setFontSize(sas, r);
  354. setAttributeSet(sas);
  355. }
  356.  
  357. }
  358. public static void main(String args[])
  359. {
  360. XMLEcoderDecoder a = new XMLEcoderDecoder();
  361. a.initialize();
  362. }
  363. }

When i insert an icon put in some styled text and change the background color of the jtextpane the file is written to disk with no exceptions
but when i try to read back the same file only the previously background color is reloaded but the styled text and embedded icon are gone.

The thing is when i replace both the XMLEncoder and XMLDecoder with
ObjectOutputStream and ObjectInputStream respectively everything works fine.

I don't know why can't serialize objects of my jtextpane but am i missing something.

I hope someone can help me with this problem

Thank You

Yours Sincerely

Richard West
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1
Reputation: srikanth_mcis is an unknown quantity at this point 
Solved Threads: 0
srikanth_mcis srikanth_mcis is offline Offline
Newbie Poster

Re: JTextPane

 
0
  #2
Aug 18th, 2005
i want this program in JApplete ,pls help ,i ll try to change but it is not working ,giving so many errors,pls help me as early as posible

Originally Posted by freesoft_2000
Hi everyone,

I am currently trying to serialize parts of a jtextpane using the java ObjectOutputStream to write it to disk and when i am reading the object back i am using the java ObjectInputStream.

When i read the api about the streams here is what they say



After reading this i decided to serialize my jtextpane objects using the above
xml format but could not get it to work

I am providing a ruunable example so you guys can compile the source code and see what i mean

  1.  
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.io.*;
  5. import java.util.*;
  6. import java.beans.*;
  7. import javax.swing.*;
  8. import javax.swing.event.*;
  9. import javax.swing.text.*;
  10. import javax.swing.text.rtf.*;
  11.  
  12. public class XMLEcoderDecoder implements ActionListener, ItemListener
  13. {
  14.  
  15. JFrame mainFrame = new JFrame("Frame");
  16.  
  17. JLabel labelerror = new JLabel(" ", SwingConstants.RIGHT);
  18. JButton bLoad = new JButton("Load");
  19. JButton bSaveAs = new JButton("Save as");
  20. JButton bSave = new JButton("Save");
  21. JButton bInsertPic = new JButton("Insert picture");
  22. JButton bBackgroundColor = new JButton("Set background color");
  23.  
  24. JFileChooser selectedFile = new JFileChooser();
  25. JFileChooser insertIconFile = new JFileChooser();
  26.  
  27. JColorChooser backgroundChooser = new JColorChooser();
  28.  
  29. Color backgroundColor;
  30.  
  31. JComboBox fontFamily;
  32. JComboBox fontSize = new JComboBox();
  33.  
  34. JTextPane mainTextPane = new JTextPane();
  35.  
  36. SimpleAttributeSet sas = new SimpleAttributeSet();
  37.  
  38. StyleContext sc = new StyleContext();
  39.  
  40. MutableAttributeSet mas;
  41.  
  42. DefaultStyledDocument dse = new DefaultStyledDocument(sc);
  43.  
  44. JScrollPane mainScrollPane = new JScrollPane(mainTextPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
  45. ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  46.  
  47. RTFEditorKit rtfkit = new RTFEditorKit();
  48.  
  49. Dimension Size1 = new Dimension();
  50.  
  51. String SF = "";
  52.  
  53. public void initialize ()
  54. {
  55. Container pane = mainFrame.getContentPane();
  56. pane.setLayout(new FlowLayout());
  57. mainFrame.setSize(250,300);
  58. mainFrame.setLocation(300,300);
  59. mainFrame.setBackground(Color.lightGray);
  60. //The below command line is the JTextPane using the rtf editor kit
  61. //for any rtf editing
  62.  
  63. mainTextPane.setEditorKit(rtfkit);
  64. //The below command line sets the document that the JTextPane will be
  65. //be referencing to
  66.  
  67. mainTextPane.setDocument(dse);
  68. Size1.width = 500;
  69. Size1.height = 300;
  70. mainScrollPane.setPreferredSize(Size1);
  71. pane.add(mainScrollPane);
  72. pane.add(bLoad);
  73. pane.add(bSaveAs);
  74. pane.add(bSave);
  75. pane.add(bInsertPic);
  76. pane.add(bBackgroundColor);
  77.  
  78. combofontfamilyinitialize();
  79. pane.add(fontFamily);
  80. combofontsizeinitialize();
  81. pane.add(fontSize);
  82. pane.add(labelerror);
  83.  
  84. mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  85. bLoad.addActionListener(this);
  86. bSaveAs.addActionListener(this);
  87. bSave.addActionListener(this);
  88. bInsertPic.addActionListener(this);
  89. bBackgroundColor.addActionListener(this);
  90.  
  91. fontFamily.addItemListener(this);
  92. fontSize.addItemListener(this);
  93. mainFrame.pack();
  94. mainFrame.setVisible(true);
  95. }
  96.  
  97. public void combofontfamilyinitialize ()
  98. {
  99. //This function fills the combo box with the system available font families
  100.  
  101. GraphicsEnvironment ge1 = GraphicsEnvironment.getLocalGraphicsEnvironment();
  102. String[] k = ge1.getAvailableFontFamilyNames();
  103. fontFamily= new JComboBox(k);
  104. }
  105.  
  106. public void combofontsizeinitialize ()
  107. {
  108. //This function fills the combo box with font sizes
  109.  
  110. fontSize.addItem("8");
  111. fontSize.addItem("9");
  112. fontSize.addItem("10");
  113. fontSize.addItem("11");
  114. fontSize.addItem("12");
  115. fontSize.addItem("14");
  116. fontSize.addItem("16");
  117. fontSize.addItem("18");
  118. fontSize.addItem("20");
  119. fontSize.addItem("22");
  120. fontSize.addItem("24");
  121. fontSize.addItem("26");
  122. fontSize.addItem("28");
  123. fontSize.addItem("36");
  124. fontSize.addItem("48");
  125. fontSize.addItem("72");
  126. }
  127.  
  128. public void setAttributeSet(AttributeSet attr)
  129. {
  130.  
  131. //This function only set the specified font set by the
  132. //attr variable to the text selected by the mouse
  133.  
  134. int xStart, xFinish, k;
  135.  
  136. xStart = mainTextPane.getSelectionStart();
  137. xFinish = mainTextPane.getSelectionEnd();
  138. k = xFinish - xStart;
  139.  
  140. if(xStart != xFinish)
  141. {
  142. dse.setCharacterAttributes(xStart, k, attr, false);
  143. }
  144.  
  145. else if(xStart == xFinish)
  146. {
  147. //The below two command line updates the JTextPane according to what
  148. //font that is being selected at a particular moment
  149.  
  150. mas = rtfkit.getInputAttributes();
  151. mas.addAttributes(attr);
  152. }
  153. //The below command line sets the focus to the JTextPane
  154.  
  155. mainTextPane.grabFocus();
  156. }
  157.  
  158. public void open ()
  159. {
  160.  
  161. if(selectedFile.showOpenDialog(mainFrame) != JFileChooser.APPROVE_OPTION)
  162. {
  163. return;
  164. }
  165.  
  166. try
  167. {
  168. File file1 = selectedFile.getSelectedFile();
  169. SF = file1.toString();
  170. FileInputStream fStream = new FileInputStream(SF);
  171. XMLDecoder stream = new XMLDecoder(fStream);
  172.  
  173. Object obj;
  174. int i = 0;
  175.  
  176. //The below for loop reads in all the two objects required
  177. //for the initialization of the objects in the program
  178.  
  179. for(i=0;i<2;i++)
  180. {
  181. //The below command line reads the first object in the file
  182.  
  183. obj = stream.readObject();
  184.  
  185. //The below command line initializes the first object in the file
  186. //coresponding to the objects in the program
  187.  
  188. loadinitialize(obj);
  189. }
  190.  
  191. stream.close();
  192. fStream.close();
  193. }
  194.  
  195. catch (Exception e)
  196. {
  197. labelerror.setText("A document reading error has occured");
  198. }
  199.  
  200. }
  201.  
  202. public void loadinitialize(Object Object1)
  203. {
  204. //This function initilizes all the objects in the program according
  205. //to the loading of a new file
  206.  
  207. if(Object1 instanceof DefaultStyledDocument)
  208. {
  209. //The document must be first read into the DefaultStyledDocument
  210. //before any document rendering can be done to it
  211.  
  212. dse = ((DefaultStyledDocument)Object1);
  213. mainTextPane.setDocument(dse);
  214. }
  215.  
  216. else if(Object1 instanceof Color)
  217. {
  218. //The below command line loads the color as an object
  219. //using the user specified file name and sets the color
  220. //to the current JTextPane
  221.  
  222. mainTextPane.setBackground((Color)Object1);
  223. }
  224.  
  225. }
  226.  
  227. public void saveas ()
  228. {
  229.  
  230. if(selectedFile.showSaveDialog(mainFrame) != JFileChooser.APPROVE_OPTION)
  231. {
  232. return;
  233. }
  234.  
  235. try
  236. {
  237. File file2 = selectedFile.getSelectedFile();
  238. SF = (file2.toString() + ".xml");
  239. FileOutputStream fStream = new FileOutputStream(SF);
  240. XMLEncoder stream = new XMLEncoder(fStream);
  241. stream.writeObject(mainTextPane.getDocument());
  242. stream.writeObject(mainTextPane.getBackground());
  243. stream.flush();
  244. stream.close();
  245. fStream.close();
  246. }
  247.  
  248. catch (Exception e)
  249. {
  250. labelerror.setText("A document writing error has occured");
  251. }
  252.  
  253. }
  254.  
  255. public void save ()
  256. {
  257.  
  258. try
  259. {
  260. String str1 = SF;
  261.  
  262. if(str1.equals(""))
  263. {
  264. saveas();
  265. return;
  266. }
  267.  
  268. FileOutputStream fStream = new FileOutputStream(str1);
  269. XMLEncoder stream = new XMLEncoder(fStream);
  270. stream.writeObject(mainTextPane.getDocument());
  271. stream.writeObject(mainTextPane.getBackground());
  272. stream.flush();
  273. stream.close();
  274. fStream.close();
  275. }
  276.  
  277. catch (Exception e)
  278. {
  279. labelerror.setText("A document writing error has occured");
  280. }
  281.  
  282. }
  283.  
  284. public void actionPerformed(ActionEvent event)
  285. {
  286. JComponent b = (JComponent)event.getSource();
  287. String str3 = null;
  288.  
  289. if(b == bLoad)
  290. {
  291. open();
  292. }
  293.  
  294. else if(b == bSaveAs)
  295. {
  296. saveas();
  297. }
  298.  
  299. else if(b == bSave)
  300. {
  301. save();
  302. }
  303.  
  304. else if(b == bInsertPic)
  305. {
  306.  
  307. insertIconFile.setDialogType(JFileChooser.OPEN_DIALOG);
  308. insertIconFile.setDialogTitle("Select a picture to insert into document");
  309.  
  310. if(insertIconFile.showDialog(mainFrame,"Insert") != JFileChooser.APPROVE_OPTION)
  311. {
  312. return;
  313. }
  314.  
  315. File g = insertIconFile.getSelectedFile();
  316. ImageIcon image1 = new ImageIcon(g.toString());
  317. mainTextPane.insertIcon(image1);
  318. mainTextPane.grabFocus();
  319. }
  320.  
  321. else if(b == bBackgroundColor)
  322. {
  323.  
  324. backgroundColor = backgroundChooser.showDialog(mainFrame, "Color Chooser", Color.white);
  325.  
  326. if(backgroundColor != null)
  327. {
  328. mainTextPane.setBackground(backgroundColor);
  329. }
  330.  
  331. }
  332.  
  333. }
  334.  
  335. public void itemStateChanged(ItemEvent event)
  336. {
  337. JComponent c = (JComponent)event.getSource();
  338. boolean d;
  339.  
  340. if(c == fontFamily)
  341. {
  342.  
  343. String j = (String)fontFamily.getSelectedItem();
  344. StyleConstants.setFontFamily(sas, j);
  345. setAttributeSet(sas);
  346. }
  347.  
  348. else if(c == fontSize)
  349. {
  350.  
  351. String h = (String)fontSize.getSelectedItem();
  352. int r = Integer.parseInt(h);
  353. StyleConstants.setFontSize(sas, r);
  354. setAttributeSet(sas);
  355. }
  356.  
  357. }
  358. public static void main(String args[])
  359. {
  360. XMLEcoderDecoder a = new XMLEcoderDecoder();
  361. a.initialize();
  362. }
  363. }

When i insert an icon put in some styled text and change the background color of the jtextpane the file is written to disk with no exceptions
but when i try to read back the same file only the previously background color is reloaded but the styled text and embedded icon are gone.

The thing is when i replace both the XMLEncoder and XMLDecoder with
ObjectOutputStream and ObjectInputStream respectively everything works fine.

I don't know why can't serialize objects of my jtextpane but am i missing something.

I hope someone can help me with this problem

Thank You

Yours Sincerely

Richard West
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: JTextPane

 
0
  #3
Aug 18th, 2005
Richard, could it be the XML serialiser isn't correctly serialising the graphical (thus binary) data, leading to your document being corrupted?
I've not used the system, but seeing as XML was never meant for binary data that is a likely scenario.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC