I've got a String that was a JInternalFrame.toString() I've written to a file, and now I need a way to load that back as a JInternalFrame. The string of data looks like
javax.swing.JInternalFrame[,0,0,500x400,invalid,hidden,layout=javax.swing.plaf.basic.BasicInternalFrameUI$Handler,alignmentX=0.0,alignmentY=0.0,border=com.apple.laf.AquaInternalFrameUI$CompoundUIBorder@2e00e753,flags=16777216,maximumSize=,minimumSize=java.awt.Dimension[width=150,height=65],preferredSize=,closable=true,defaultCloseOperation=DISPOSE_ON_CLOSE,desktopIcon=javax.swing.JInternalFrame$JDesktopIcon[,0,0,64x64,invalid,hidden,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=],frameIcon=,iconable=false,isClosed=false,isIcon=false,isMaximum=false,isSelected=false,maximizable=true,opened=false,resizable=true,rootPane=javax.swing.JRootPane[,0,0,0x0,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=449,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true,title=Test app]
I know a String can't be cast to a JInternalFrame, but there must be some sort of way to convert it. How would I do that?
I wouldn't try to serialize a JInternalFrame
. Why? From the Javadoc for JInternalFrame
:
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.
I would listen to the warning and look at implementing XMLEncoder
into your program instead.