Java JTextPane saveFile(JTextPane txt)

Here you can find the source of saveFile(JTextPane txt)

Description

save File

License

Open Source License

Declaration

public static void saveFile(JTextPane txt) 

Method Source Code

//package com.java2s;
/*//from  w  ww .j  a va 2 s.  com
 Copyright (c) 2016 StarFruitBrasil

 Permission is hereby granted, free of charge, to any person obtaining a copy of
 this software and associated documentation files (the "Software"), to deal in
 the Software without restriction, including without limitation the rights to
 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 the Software, and to permit persons to whom the Software is furnished to do so,
 subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all
 copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import java.io.File;

import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JTextPane;

public class Main {
    private static File diretorio = null;

    public static void saveFile(JTextPane txt) {
        FileWriter fw;
        try {
            fw = new FileWriter(getDiretorio().getAbsoluteFile(), false);
            txt.write(fw);
            fw.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static File getDiretorio() {
        return diretorio;
    }
}

Related

  1. getFontFamily(JTextPane textPane)
  2. getForegroundColor(JTextPane textPane)
  3. insertStyledString(JTextPane textPane, String text, SimpleAttributeSet attrSet, Color background, Color foreground, String fontFamily, int fontSize, boolean bold, boolean italic, boolean underline, boolean strikeThrough, Boolean superscript)
  4. isSelectionBold(JTextPane textPane)
  5. overrideStyle(String styleName, JTextPane textPane, Style newStyle)
  6. scrollTo(JTextPane textPane, int position)
  7. setDefaultTextPaneProperties(JTextPane textPane)
  8. setJTextPaneFont(JTextPane jtp, Font font, Color c)
  9. setSelectionFontSize(JTextPane textPane, int fontSize)