Results 1 to 8 of 8
  1. #1
    kostinio is offline Member
    Join Date
    Oct 2009
    Posts
    13
    Rep Power
    0

    Default jfilechooser and jtextarea problem

    Hello all,

    I work in a project and i want to open a .xml or .doc file in a text area or in a label.. whatever is easier.. I tried to use jfilechooser to do that but i didn't find any solution to do it.. I can't find the right method to get the component of a doc or xml and to show it in a label or text area.. Can anyone help me?

    Thanks in advance!!!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    A JTextArea is used to dispaly text.

    It should be able to display an XML file since XML is text.

    However, if your .doc file is a Word .doc file then it will not work. You will just see garbage, because the text area does not know how to format the file. In this case you will need to use the Destop class.

  4. #4
    kostinio is offline Member
    Join Date
    Oct 2009
    Posts
    13
    Rep Power
    0

    Default

    In my project i want the user to choose an xml file via jfilechooser and then the component of this file to be shown in a text area. I didn't find any method or the way to do it.. :confused:

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Why not use the read() method of JTextArea.

  6. #6
    kostinio is offline Member
    Join Date
    Oct 2009
    Posts
    13
    Rep Power
    0

    Default

    i want to thank all of you for your help and especially camickr because the class desktop worked.. but i want to ask something more :)

    With the class desktop the .xml file opens in a new window.. i did't figure out how to import the component of this file in the textarea. I tried to do it with:

    jTextArea1.read(filetoopen);

    (filetoopen is the file which is chosen from the user)

    but i have error in the compile...

    Does anyone have any idea? :)

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  8. #8
    kostinio is offline Member
    Join Date
    Oct 2009
    Posts
    13
    Rep Power
    0

    Default

    This is the error that occurs:

    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code
    at ptx.initComponents(ptx.java:216)
    at ptx.<init>(ptx.java:25)
    at ptx$28.run(ptx.java:826)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)

Similar Threads

  1. Replies: 17
    Last Post: 07-13-2009, 06:44 AM
  2. Jtextarea Content Display Problem
    By REVANSIDDHA in forum Advanced Java
    Replies: 1
    Last Post: 03-31-2009, 07:53 PM
  3. JFileChooser horizontal scrollbar problem
    By nenadm in forum AWT / Swing
    Replies: 4
    Last Post: 11-12-2008, 12:16 PM
  4. how to use JFileChooser
    By tommy in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 09:49 PM
  5. Replies: 0
    Last Post: 07-17-2007, 04:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •