Switching documents in JEditorPane

I have a program that creates an array of files and reads them one at a time to make an HTML document to display its contents. The problem I'm having is that I cannot change the contents of the document, I want the user to be able to sift through the array to view different info.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
public class OtherLibContact extends JScrollPane implements ActionListener     
     String [] command =     {
                                   "<<",
                                   ">>"
     String [] headers =     {
                              "Library Name",
                              "Town",
                              "Address",
                              "Librarian",
                              "Postal Code",
                              "Telephone",
                              "Fax",
                              "Email Address",
                              "Web Site",
                              "Type of Library",
                              "Hours"
     String [] days =     {
                              "Sunday",
                              "Monday",
                              "Tuesday",
                              "Wednesday",
                              "Thursday",
                              "Friday",
                              "Saturday"
     /*Variables used to list files in directory and switch between files*/
     File dir;
     File [] dirListed;
     String [] filesListed;
     String workingDir = "profiles/";
     String filename = "profiles/DBprofile.dat";
     /*Where the PLS record is located*/
     int index = 0;
     /*HTML file to be created and altered*/
     String record = "current.html";
     URL url;
     JButton [] buttons = new JButton [command.length];
     JPanel panel = new JPanel ();
     JEditorPane pane = new JEditorPane ();
     public OtherLibContact ()
          checkDir ();
          makeButtons ();
          pane.setBackground (CustomColors.getAppColor ());
          this.setViewportView (panel);
          this.setBorder (null);
          this.setBackground (CustomColors.getAppColor ());
          panel.setLayout (new BorderLayout ());
          panel.add ("North", buttons [0]);
          panel.add ("South", buttons [1]);
          panel.add ("Center", pane);
     /*Makes an array out of the files found in the workingDir*/
     public void checkDir ()
          /*makes a new file object*/
          dir = new File (workingDir);
          /*only if dir is a directory does this work*/
          if (dir.isDirectory ())
               /*lists files in file object array*/
               dirListed = dir.listFiles ();
               /*creates a string array of the same size*/
               filesListed = new String [dirListed.length];
               /*copys the file names into the string array one by one*/
               for (int i = 0; i < dirListed.length; i++)
                    filesListed = dirListed [i].getName ();
               makeHTML (workingDir +filesListed [0]);
     public void makeButtons ()
          for (int i = 0; i < buttons.length; i++)
               buttons [i] = new JButton (command [i]);
               buttons [i].setBackground (CustomColors.getAppColor ());
               buttons [i].addActionListener (this);
          buttons [0].setToolTipText ("Move back one record");
          buttons [1].setToolTipText ("Move forward one record");
     public void setScreen ()
          try
               url = new URL ("file:\\\\" +ReturnInfo.getRoot ()
                                        +record);
               pane.setPage (url);
               pane.setEditable (false);
          catch (IOException io)
               buttons [0].setText (io.toString ());
     public void makeHTML (String thisfile)
          String [] pr = readFile (thisfile);
          int offset = 0;
          /*Try to create an HTML file to display output*/
          try
               FileWriter fw = new FileWriter (record);
               BufferedWriter bw = new BufferedWriter (fw);
               PrintWriter pw = new PrintWriter (bw);
               pw.println ("<HTML>");
*Makes the HTML document here
               pw.println ("</HTML>");
               pw.close ();
               setScreen ();
          catch (IOException ioe)
               buttons [0].setText (ioe.toString ());
     public String [] readFile (String file)
          String [] fromFile = new String [38];
          /*Try to read the file*/
          try
               FileReader fr = new FileReader (file);
               BufferedReader br = new BufferedReader (fr);
               String line = br.readLine ();
               for (int i = 0; line != null; i++)
                    fromFile [i] = line;
                    line = br.readLine ();
          /*Catch errors from reading the file*/
          catch (FileNotFoundException fnfe)
               buttons [0].setText (fnfe.toString ());
          catch (IOException ioe)
               buttons [0].setText (ioe.toString ());
          return fromFile;
     public void actionPerformed (ActionEvent ae)
          Object source = ae.getSource ();
          /*'workingDir' +'filesListed' = path to files*/
          if (source == buttons [0])/*BACK*/
               File theHTML = new File (record);
               if (theHTML.isFile ())
                    theHTML.delete();
                    makeHTML (workingDir +filesListed [0]);
               else
                    makeHTML (workingDir +filesListed [0]);
          else /*NEXT*/
               File theHTML = new File (record);
               if (theHTML.isFile ())
                    theHTML.delete();
                    makeHTML (workingDir +filesListed [1]);
               else
                    makeHTML (workingDir +filesListed [1]);     
I have a different app where I use the button to refresh to contents of the HTML page after a search has been performed. I thought if I could pass a new file to it every time I could refresh the page with different content. Any and all help is apprecaited
-conor.

You can use HTMLEditorKit for this purpose.
use method createDefaultDocument() to create blank document.
after that use method
read(Reader in,Document doc,int pos);
to read content of HTML file in the Document.
and when you create list of required document just change content of JEditorPane using setDocument(Document doc); method
best regards
Stas

Similar Messages

  • Switch Document not created

    Hi,
    Need some suggestion for the below concern.
    I am trying to created switch document in IS U system from BOR Object i.e. ISUSWITCHD. But switch document is getting created with Error. I have checked the datex process is configured and updated for the service provider.
    But, while monitoring switch document it is giving Error - Datex process not found for 0985 (¿?) and G0230
    Note: Here 0985 (Service Provider) and G0230 (Distributor).
    Thanks.

    Hi,
    Check the following
    1. All the message type in the external system are correct.
    2. Check the Outbound idoc queue and take the idoc no and enter in WE02 Dispaly
    and check the reasons for the error
    Regards
    Ganesh

  • Need Technical flow of switch document creation

    Hi Experts,
    I am new to IS U and IS U CRM.
    I want to write a technical flow for the below requirement.
    When Quotation is created in CRM an contract is automatically created and switch document is generated and replicated in IS U System.
    How this switch document is created and replicated in IS U sytem? Need to know the completed technical flow of it.
    What class or BOR is called...like wise.
    Any input will be very thankful...
    Thanks,
    Parthow.

    Google for "Data Collection Technical Workshop" by Oracle employee Sanjeev Kale. It is quite good.
    Hope this helps,
    Sandeep Gandhi

  • How to create switch documents in SAP CRM?

    Hi,
    I'm trying to create switch documents in SAP CRM. I'm using method CL_CRM_ISU_ORDER_DEREG=>CREATE_SWITCH_MESSAGE but one of the parameters is CONTEXT...
    Someone knows how this parameter should be filled?
    Thanks,
    André

    Hi Andre,
    the class CL_CRM_ISU_ORDER_DEREG is used by the classes of the utilities process framework to create a switch doc in the context of a process. The context parameter is a reference to the process context. The class CL_CRM_IU_PR_CNTR_START, for example, uses  CL_CRM_ISU_ORDER_DEREG in the ON_POD_CHANGED method to create a switch doc.
    While it is possible to set up a process context in a custom program the real question is what are you trying to achieve? Maybe it is easier to solve your requirement in the context of the process framework that to start from scratch.
    Are you aware of the concepts underlying the utilities process framework? If not have a look at the following documents:
    Process Framework in Contract Management - SAP CRM for Utlilities
    https://websmp210.sap-ag.de/~sapidb/011000358700001113322009E/Utilities_Prozess_FW_en.pdf (available at SAP Service Marketplace -> Solutions -> SAP for Utilities -> SAP for Utilities - Product Information -> SAP CRM for Utilities -> Cookbooks&Guidelines -> Utilities_Prozess_FW_en.pdf )
    Best, Christian

  • IDE: automatic start of workflow for switch document

    Hello guys,
    Please, can someone tell me how do you automatically start the distributor workflow (WS20500195) without using SWUD transaction?
    I created the switch document ( switch view: distributor, switch type: end of supply), but the workflow won't start automatically, although is activated in SWE2 transaction.
    Thanks,
    Regards,
    Eduard M.

    Hello Anand,
    The workflows (distributor, new supplier, former supplier) were activated in SWE2 transaction.
    I also activated the triggering events from SWDD transaction for each workflow.
    Object type: ISUSWITCHD
    Event of the object: CREATED
    The thing is that after creating the switch document, I thought the workflow will start automatically (i mean after having customized the workflows in SPRO + SWE2 + SWDD).
    Anyway, thanks for your help.
    Best regards,

  • FM to display switch document

    Hi,
    I need a FM to display a switch document (like in TA ESWTMON01).
    Thanks in advance.
    Regards Shiva

    Hi Shiva,
    you can use Fm ISU_S_IDE_SWITCHDOC_DISPLAY.
    Hope that helps.
    KR Alexander

  • Principal difference between an Idoc and a Switch document.

    Hello
    what is the principal difference between an Idoc and a Switch document.
    Thanks

    Hi,
    A switch document documents a process, such as, switch of supplier, in a liberalized market and can be monitored with own transactions. The process steps are usually controlled by workflows.
    An IDoc is used to transfer data from one system to another one in a predefined package. When you import an IDoc containing a market message, a workflow can be started creating/updating switch documents.
    Kind regards,
    Fritz

  • Is there a way to cache documents in JEditorPane ?

    I am using a JEditorPane to load html pages.
    some of my pages are quite big and take some time to load. I would like to cache the pages so the next time the user loads a cached page, the page will load very quickly.
    It seems that what I need to cache is the html document that represents the model. However using JEditorPane setDocument( ) method with the cached document takes the same time as loading a new page.
    so perhaps i need to cache the views also ?
    thanks.

    1. I load documents only from the local drive.
    2. The pages I load can be quite big.
    3. I load the pages synchronically
    I have measured a bit of times for loading a big page.
    when the page is new it takes 11 seconds to build the document. with a cached document it takes about 7 seconds.
    the painting of the views takes little time.
    my question is: if I supply the editor pane with a fully built document model, why does it still take him 7 seconds to ready it?
    or if someone knows a way to load a cached document instead of using the setDocument( ) method.
    Thanks

  • Shortcut to switch document windows not working?

    Greetings,
    I'm using CS3 5.0.3 on OS 10.4.11.
    I'm trying to use a shortcut to switch between different open document windows. The documentation says this:
    Switch to next/previous document window
    Command+F6 or Command+~ [tilde]/ Command+Shift+~ [tilde]
    However, none of these options work.
    Any ideas? Thanks in advance!

    Hi,
    I'm not quite sure if it has worked before because I've just recently started using ID more often (finally got Q2ID).
    I tried both of your suggestions, but neither helped.
    So still looking for an answer.... but thanks for the input.

  • Alt key switching documents instead of Creating Clipping Mask - New Mac Pro 2014 - Please help

    I just got a new Mac Pro, and when I use the alt/option key as a shortcut in the layers palette (to create clipping masks and duplicate layers) instead it switches to other documents that I have open.  It's only after this happened that I realized how often I use the option key in my work flow and it's frustrating. 
    Please help,
    Thanks,
    Lonno

    Just solved it.  It had to do with my secondary monitor, which is where my layers palette was.  I used this link:
    https://discussions.apple.com/thread/5476222?tstart=0
    and turned off all the mission control settings I don't use.  Apparently it was switching monitors whenever I used the alt key.
    -Lonno

  • Displaying Word document in JEditorPane

    Hi,
    I (urgently) need to display a .doc file in a JEditorPane component..
    Can anyone sent here some simply piece of code??
    Thanx in advance!!
    Dewsqa

    Hey
    did you manage to find that out! Im trying to do the same, only have hours left to do so!
    If anyone knows how, please let me know.
    I have it all set up to display the file, just it will only read .txt files. How do you get it to display word docs?
    pane = new JEditorPane();
            try {
                pane.getEditorKit().read(new java.io.FileReader("file.doc"), pane.getDocument(), 0);
                pane.setEditable(false);
            catch (Exception e) {
                e.printStackTrace();
            Thanks Much appreciated

  • How to insert hyperlinks in RTF document shown in JEditorPane?

    This is a compound question so bear with me on this one :)
    What I need is to insert an hyperlink in a JEditorPane; Store it as RTF code; Retrieve it; Show it and click on it to go the the destination.
    1) So, first question, is there some method to automatically add the hyperlink and will it be saved in RTF with RTFEditorKit? (I'm actually using AdvancedRTFEditorKit but an answer to either will be enough)
    2) I tried a method that adds what appears as a link but the document that is stored doesn't have the necessary RTF codes, only the formatting that makes it look like a link. I also checked the actual RTF codes I'd need to add and they seem easy to do. So, is there a way to add the actual underlying RTF codes to the document while it's in the JEditorPane?
    I know the question(s) isn't too specific, if you can shed some light over the whole thing and point me in the right direction, it'd be great!

    Just a follow up to my own question. I found a way to answer my question 2) and I'm now storing the rtf code for hyperlinks. Now, when I show the document in JEditorPane with RTFEditorKit, I get the name of the hyperlink with no formatting indicating that it's a hyperlink.
    Example. The link "http://www.google.com" with the name "Google", only shows "Google" in plain text.
    Is it because the components I'm using don't support hyperlinks from RTF files even though they're supported from HTML files?
    Is there any way you can see this working? Is it possible to include something inside the JEditorPane that the user can click, instead of the hyperlink?

  • JEditorPane - backmapping highlighted text to source html document

    Hello everyone,
    I have the following problem: I display a HTML document in JEditorPane. Then I highlight some chunk of text and get the start and the end selection offsets by using getSelectionStart() and getSelectionEnd() methods, respectively. What I would like to know is the exact position (character offset) of the highlighted text in the original HTML document that is being displayed.
    Does anybody know the solution for that?
    Thanks.

    I don't think it's possible. The parser builds a Document out of the text and doesn't keep the original source text. For example if your html is like this:
    String text = "<html><body>     some     text     </body></html>";All the multiple spaces between the text is parsed out.
    Use a JTextPane and use attributes. Its easier to work with than using HTML.

  • [CS4 JS] ScriptUI - Update palette with properties from front document

    Hi all. I have created, with ScriptUI, a palette containing, among other things, a ListBox containing items for every xmlElement in a document. I want the control to read from the front document when there is more than one document open, and to update when there is a new front document.
    I've added event listeners for "afterRevert," "afterOpen," "afterNew" and "afterClose" that call the function that populates the ListBox. The ListBox is successfully updated on closing the front document, reverting, or making a new document, or when opening a document when no others are open. However:
    1.) The control doesn't update when a second or third document is opened. It "hangs on" to the first document. I've tried defining my document variable, in the function called by the event listeners, as app.documents.item(0) and as app.activeDocument, with no change in behavior. And
    2.) I don't know how to update the control when bringing to the front an already-open document. I've tried adding an onActivate listener to my palette window that calls the ListBox population function, but the palette window isn't deactivated when you change the front document using command-~ or the Window menu, so it only works if you switch documents by clicking their tabs in the application window.
    Can anyone help me? I think I'm missing something basic in my approach. If not, I can clean up some code to post.
    Thanks,
    Jeff

    2.) I don't know how to update the control when bringing to the front an already-open document. I've tried adding an onActivate listener to my palette window that calls the ListBox population function, but the palette window isn't deactivated when you change the front document using command-~ or the Window menu, so it only works if you switch documents by clicking their tabs in the application window.
    Perhaps adding an eventListener to the appropriate menuItems (that changes the activeDocument) to update your palette will do the trick?

  • I need to work on documents in both my iMac and air book. But I have to download document and them upload it, and when I upload it I can't open it unless I open it on my phone first. Yet changes made on phone appear straight away. Does this make sense????

    I need to work on documents in both my iMac and air book. But I have to download document and them upload it, and when I upload it I can't open it unless I open it on my phone first. Yet changes made on phone appear straight away. Does this make sense????

    On your Macs open System Preferences > iCloud
    Deselect the box next to Documents & Data, then reselect that box then restart your Macs.
    On the iPhone tap Settings > iCloud. Switch Documents & Data off then back on then reset the iPhone.
    Hold the On/Off Sleep/Wake button and the Home button down at the same time for at least ten seconds, until the Apple logo appears.
    See if you can open the files now without opening on the iPhone first.

Maybe you are looking for

  • How to make Mavericks faster on an "older" MacBook Pro?

    I have a late 2011 MacBook Pro, 2.2 GHz core i7 with 4 GB of RAM. I recently wiped my computer and restored to factory settings because it was getting slow, then I upgraded to Mavericks and it is even slower. It freezes often and takes a long time to

  • Time Capsule user account

    I use Lion OSX I have created 2 user accounts on my time capsule in order to backup 2 different macs in the respective user's directories. When i try to restore one of my mac from scratch using "Restore System from Backup", inserting user account and

  • Help: Compiling mod_jk2 in solaris 10

    Hi everyone, I am trying to setup apache (bundled with Xampp) to work with tomcat through the jk connector. My server is Solaris SPARC 10. I couldn't find the binary distribution of mod_jk2 for Solaris 10 on the net (any one have it ????), Iam trying

  • IPhoto Sharing with iCloud

    Hi, I followed the instructions to use iPhoto on my IMac. There's a problem with IPhoto. On the iCloud pages, it's written that I must update IPhoto. But it seems that my iPhoto 11 is up to date. When I go to iPhoto, there's no way I can see ICloud t

  • Placing an image on top of existing image

    I seem to have a lot of trouble with placing an image on top of an existing image and then wanting it to stay relative to the original. As in... I want to put a button on an image of a map. Then later.. will make a hotspot on that area to open anothe