Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: saving a jTextPane input

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default saving a jTextPane input

        private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
            // TODO add your handling code here:
     
            FileDialog nameBox;
            nameBox = new FileDialog(this, "Save Peptides",FileDialog.SAVE);
            nameBox.setVisible(true);
            String fileDirectory = nameBox.getDirectory();
            String savename = nameBox.getFile();
            savename = fileDirectory.concat(savename);
     
            JTextPane in = jTextPane3; 
            try (PrintWriter pWriter = new PrintWriter(new FileWriter(savename))) {
                pWriter.println(in);
            } catch (IOException ex) {
                Logger.getLogger(VeiwJFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
     
     
        }

    this brings up my filechooser and allowes to to save the file only problem is is saves

    "javax.swing.JTextPane[,0,-15,6144x44,layout=javax.swing.plaf.basic.BasicText UI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,bor der=javax.swing.plaf.basic.BasicBorders$MarginBord er@1c1e333,flags=296,maximumSize=,minimumSize=,pre ferredSize=,caretColor=sun.swing.PrintColorUIResou rce[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResourc e[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIRes ource[top=3,left=3,bottom=3,right=3],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],kit=javax.swing.text.html.HTMLEditorKit@f53870,ty peHandlers={text/html=javax.swing.text.html.HTMLEditorKit@f53870, text/plain=javax.swing.text.StyledEditorKit@14c4ac9}]
    "

    instead of the text insided the jtextpanel.

    any help would be appreciated.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: saving a jTextPane input

    Read the API doc to see if the class has methods that will return the data that you want.
    What you posted looks like the String that is returned by the toString() method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    mrgregglles (November 10th, 2013)

  4. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: saving a jTextPane input

    Then save JTextPane.getText() rather than the specifics of the JTextPane itself.

  5. The Following User Says Thank You to GregBrannon For This Useful Post:

    mrgregglles (November 10th, 2013)

  6. #4
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: saving a jTextPane input

    thanks guys sorry for such a simple question its been a long assignment week

Similar Threads

  1. How to enable wrapping in JTextPane
    By kcaz in forum AWT / Java Swing
    Replies: 7
    Last Post: December 2nd, 2012, 04:04 PM
  2. JTextPane changing text color issues
    By donnierisk in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 30th, 2012, 11:29 AM
  3. JTextPane questions.
    By sunde in forum AWT / Java Swing
    Replies: 1
    Last Post: March 28th, 2011, 03:18 PM
  4. [SOLVED] JTextPane focus problem
    By LeonLanford in forum AWT / Java Swing
    Replies: 3
    Last Post: June 21st, 2010, 11:50 PM
  5. Java JTextPane Save
    By ikurtz in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: April 28th, 2010, 01:02 AM