Text file documents allow a Java™ program to use any Java Foundation Classes (JFC) graphical text component to edit or view text files in the integrated file system on a server. (A text component is a graphical component used to display text that the user can optionally edit.)
The IFSTextFileDocument class is an implementation of the JFC Document interface. It can be used directly with any JFC graphical text component. Several text components, such as single line fields (JTextField) and multiple line text areas (JTextArea), are available in JFC.
Text file documents associate the contents of a text component with a text file. The Java program can load and save between the text component and the text file at any time.
To use an IFSTextFileDocument, set both the system and path properties. These properties can be set using a constructor or through the setSystem() and setPath() methods. The IFSTextFileDocument object is then "plugged" into the text component, typically using the text component's constructor or setDocument() method.
Initially, the contents of the text component are empty. Use load() to load the contents from the text file. Use save() to save the contents of the text component to the text file.
The following example creates and loads an IFSTextFileDocument:
// Create and load the // IFSTextFileDocument object. Assume // that "system" is an AS400 object // created and initialized elsewhere. IFSTextFileDocument ifsDocument = new IFSTextFileDocument (system, "/DirectoryA/MyFile.txt"); ifsDocument.load (); // Create a text area to present the // document. JTextArea textArea = new JTextArea (ifsDocument); // Add the text area to a frame. // Assume that "frame" is a JFrame // created elsewhere. frame.getContentPane ().add (textArea);Example
Present an IFSTextFileDocument in a JTextPane.
Figure 1 shows the IFSTextFileDocument graphical user interface component:
Figure 1: IFSTextFileDocument example