Results 1 to 16 of 16
  1. #1
    captain alge is offline Member
    Join Date
    Mar 2011
    Posts
    25
    Rep Power
    0

    Default Document variable

    Just a quick and probably silly question, how do I set a document variable? I imagine it's is something like :

    Java Code:
    Document myDoc = new Document("C:/folder/file");
    but that doesn't seem to work...
    (I get an error saying javax.swing.text.Document is abstract, can not be instantiated)

    cheers!
    Last edited by captain alge; 03-27-2011 at 10:04 AM.

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default

    Would File work?

    Plus, remember that "/" is the escape character. For a literal forward slash, use "//".

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Document is abstract as the error suggests. Go to the document API and find a concrete implementation( I think DefaultStyledDocument) is one type.

  4. #4
    captain alge is offline Member
    Join Date
    Mar 2011
    Posts
    25
    Rep Power
    0

    Default

    No, apparently I need a document

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Good luck instantiating an interface. If we are thinking of the same thing, a document is an interface. You can't create an instance of it, instead you create an instance of a class that implements the document interface. Google java 6 document.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Iron Lion View Post
    Would File work?

    Plus, remember that "/" is the escape character. For a literal forward slash, use "//".
    Nope, it's the backslash that's the escape character; also Document is an interface, you can't instantiate it. You have to find a non-abstract class that implements the interface (the API documentation will help you) and instantiate that.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default

    how do I set a document variable?
    Without adequate background information, nobody is going to be able to answer that. What exactly are you aiming to do? (note, 'what', not 'how')

    db

  8. #8
    captain alge is offline Member
    Join Date
    Mar 2011
    Posts
    25
    Rep Power
    0

    Default

    forget it, I found an alternative way of doing what I wanted

  9. #9
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Alright, what were you trying to do exacty? If you are done please mark your thread solved with the thread tools at the top.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default

    Quote Originally Posted by captain alge View Post
    forget it, I found an alternative way of doing what I wanted
    Good show! I'm sure many here will remember that and quickly forget about any future questions you might have.

    db

  11. #11
    captain alge is offline Member
    Join Date
    Mar 2011
    Posts
    25
    Rep Power
    0

    Default

    I was trying to set the content of a text area to be the contents of a file

    used:
    Java Code:
    FileReader input = new FileReader(new File(locationoffile));
    myTextArea.read(input, evt);
    instead

    @Darryl.Burke not sure what your problem is

  12. #12
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You seemed like you came here, ignored advice and then just said nevermind.

    You weren't actually looking for a document.

  13. #13
    captain alge is offline Member
    Join Date
    Mar 2011
    Posts
    25
    Rep Power
    0

    Default

    The advice wasn't particularly helpful, you think I hadn't already checked the API?

    I didn't realise I didn't require a document, otherwise I wouldn't have posted

  14. #14
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Your original question was overly vague and that's why we weren't able to provide you with a solid answer.

  15. #15
    captain alge is offline Member
    Join Date
    Mar 2011
    Posts
    25
    Rep Power
    0

    Default

    yes I realize that now, and I apologize for that.
    But at the time I thought it was a perfectly reasonable statement, I just assumed a Document was a form of File, but obviously I was wrong...

  16. #16
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    When you post in the forums in the future please try to be as clear as possible, people jere are very literal.

Similar Threads

  1. How to set Document Filter
    By nimishalex in forum New To Java
    Replies: 2
    Last Post: 12-27-2010, 01:08 PM
  2. Replies: 11
    Last Post: 07-07-2010, 06:02 AM
  3. Building a document from a DOM
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-03-2008, 09:22 AM
  4. Parsed Document
    By nick211001 in forum New To Java
    Replies: 1
    Last Post: 07-29-2007, 01:53 AM
  5. add a xml document
    By Jack in forum XML
    Replies: 2
    Last Post: 07-04-2007, 09:21 AM

Posting Permissions

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