Example usage for javax.swing JTextArea read

List of usage examples for javax.swing JTextArea read

Introduction

In this page you can find the example usage for javax.swing JTextArea read.

Prototype

public void read(Reader in, Object desc) throws IOException 

Source Link

Document

Initializes from a stream.

Usage

From source file:MetalModExample.java

public static JComponent makeExamplePane() {
    JTextArea text = new JTextArea();
    try {/*from ww  w  . ja v  a  2  s. c  o m*/
        text.read(new FileReader("MetalModExample.java"), null);
    } catch (IOException ex) {
    }

    JScrollPane scroll = new JScrollPane(text);
    return scroll;
}

From source file:misc.TextAreaPrintingDemo.java

private void load(JTextArea comp, String fileName) {
    try {//from  w  ww  .  j a  v a 2s .c o  m
        comp.read(new InputStreamReader(getClass().getResourceAsStream(fileName)), null);
    } catch (IOException ex) {
        // should never happen with the resources we provide
        ex.printStackTrace();
    }
}

From source file:net.sf.firemox.deckbuilder.DeckRules.java

/**
 * Create a new instance of DeckRules//from   w w  w  .  j  a va 2s  . com
 * 
 * @param parent
 */
public DeckRules(JFrame parent) {
    super(LanguageManager.getString("jdeckrules", MdbLoader.getTbsFullName()),
            LanguageManager.getString("jdeckrules.tooltip", MdbLoader.getTbsFullName()), "wiz_library_wiz.png",
            LanguageManager.getString("close"), 490, 300);
    // ... Set initial text, scrolling, and border.
    final JTextArea textRules = new JTextArea();
    textRules.setEditable(false);
    textRules.setLineWrap(true);
    textRules.setWrapStyleWord(true);
    textRules.setAutoscrolls(true);
    textRules.setTabSize(2);
    textRules.setText("No defined rules");
    BufferedReader inGPL = null;
    try {
        inGPL = new BufferedReader(new FileReader(MToolKit.getTbsFile(
                "decks/DECK_CONSTRAINTS-" + LanguageManager.getLanguage().getLocale() + "-lang.info")));
        textRules.read(inGPL, "Deck constraints");
    } catch (IOException e) {
        // Ignore this error
    } finally {
        IOUtils.closeQuietly(inGPL);
    }

    final JScrollPane scrollingArea = new JScrollPane(textRules);
    gameParamPanel.add(scrollingArea);
    pack();
}

From source file:net.sf.firemox.ui.component.SplashScreen.java

/**
 * Create a new instance of this class./* w ww  .j  av a 2s . c  om*/
 * 
 * @param filename
 *          the picture filename.
 * @param parent
 *          the splash screen's parent.
 * @param waitTime
 *          the maximum time before the screen is hidden.
 */
public SplashScreen(String filename, Frame parent, int waitTime) {
    super(parent);
    getContentPane().setLayout(null);
    toFront();
    final JLabel l = new JLabel(new ImageIcon(filename));
    final Dimension labelSize = l.getPreferredSize();
    l.setLocation(0, 0);
    l.setSize(labelSize);
    setSize(labelSize);

    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation(screenSize.width / 2 - labelSize.width / 2, screenSize.height / 2 - labelSize.height / 2);

    final JLabel mp = new JLabel(IdConst.PROJECT_DISPLAY_NAME);
    mp.setLocation(30, 305);
    mp.setSize(new Dimension(300, 30));

    final JLabel version = new JLabel(IdConst.VERSION);
    version.setLocation(235, 418);
    version.setSize(new Dimension(300, 30));

    final JTextArea disclaimer = new JTextArea();
    disclaimer.setEditable(false);
    disclaimer.setLineWrap(true);
    disclaimer.setWrapStyleWord(true);
    disclaimer.setAutoscrolls(true);
    disclaimer.setFont(MToolKit.defaultFont);
    disclaimer.setTabSize(2);

    // Then try and read it locally
    Reader inGPL = null;
    try {
        inGPL = new BufferedReader(new InputStreamReader(MToolKit.getResourceAsStream(IdConst.FILE_LICENSE)));
        disclaimer.read(inGPL, "");
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(inGPL);
    }

    final JScrollPane disclaimerSPanel = new JScrollPane();
    disclaimerSPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    disclaimerSPanel.setViewportView(disclaimer);
    disclaimerSPanel.setLocation(27, 340);
    disclaimerSPanel.setPreferredSize(new Dimension(283, 80));
    disclaimerSPanel.setSize(disclaimerSPanel.getPreferredSize());

    getContentPane().add(disclaimerSPanel);
    getContentPane().add(version);
    getContentPane().add(mp);
    getContentPane().add(l);

    final int pause = waitTime;
    final Runnable waitRunner = new Runnable() {
        public void run() {
            try {
                Thread.sleep(pause);
                while (!bKilled) {
                    Thread.sleep(200);
                }
            } catch (InterruptedException e) {
                // Ignore this error
            }
            setVisible(false);
            dispose();
            MagicUIComponents.magicForm.toFront();
        }
    };

    // setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            setVisible(false);
            dispose();
            if (MagicUIComponents.magicForm != null)
                MagicUIComponents.magicForm.toFront();
        }
    });
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                setVisible(false);
                dispose();
                MagicUIComponents.magicForm.toFront();
            }
        }
    });
    setVisible(true);
    start(waitRunner);
}

From source file:net.sf.firemox.ui.wizard.About.java

/**
 * Creates a new instance of About <br>
 * /*from  w ww  . java2s .c o  m*/
 * @param parent
 */
public About(JFrame parent) {
    super(LanguageManager.getString("wiz_about.title"), LanguageManager.getString("wiz_about.description"),
            "mp64.gif", LanguageManager.getString("close"), 420, 620);
    JPanel thanksPanel = new JPanel();

    thanksPanel.setLayout(new BoxLayout(thanksPanel, BoxLayout.X_AXIS));
    thanksPanel.setMaximumSize(new Dimension(32767, 26));
    thanksPanel.setOpaque(false);
    JLabel jLabel5 = new JLabel(LanguageManager.getString("version") + " : ");
    jLabel5.setFont(MToolKit.defaultFont);
    jLabel5.setHorizontalAlignment(SwingConstants.RIGHT);
    jLabel5.setMaximumSize(new Dimension(100, 16));
    jLabel5.setMinimumSize(new Dimension(100, 16));
    jLabel5.setPreferredSize(new Dimension(100, 16));
    thanksPanel.add(jLabel5);
    jLabel5 = new JLabel(IdConst.VERSION);
    thanksPanel.add(jLabel5);
    gameParamPanel.add(thanksPanel);

    thanksPanel = new JPanel();
    thanksPanel.setLayout(new BoxLayout(thanksPanel, BoxLayout.X_AXIS));
    thanksPanel.setOpaque(false);
    JPanel thanksPanelLeft = new JPanel(new FlowLayout(FlowLayout.LEADING));
    thanksPanelLeft.setLayout(new BoxLayout(thanksPanelLeft, BoxLayout.Y_AXIS));
    thanksPanelLeft.setMaximumSize(new Dimension(100, 2000));
    thanksPanelLeft.setMinimumSize(new Dimension(100, 16));
    jLabel5 = new JLabel(LanguageManager.getString("thanks") + " : ");
    jLabel5.setFont(MToolKit.defaultFont);
    jLabel5.setHorizontalAlignment(SwingConstants.RIGHT);
    jLabel5.setMaximumSize(new Dimension(100, 16));
    jLabel5.setMinimumSize(new Dimension(100, 16));
    jLabel5.setPreferredSize(new Dimension(100, 16));
    thanksPanelLeft.add(jLabel5);
    thanksPanel.add(thanksPanelLeft);
    thanksPanelLeft = new JPanel();
    thanksPanelLeft.setLayout(new BoxLayout(thanksPanelLeft, BoxLayout.Y_AXIS));
    StringBuilder contributors = new StringBuilder();
    addContributor(contributors, "Fabrice Daugan", "developper", "france");
    addContributor(contributors, "Hoani Cross", "developper", "frenchpolynesia");
    addContributor(contributors, "nico100", "graphist", "france");
    addContributor(contributors, "seingalt_tm", "graphist", "france");
    addContributor(contributors, "surtur2", "tester", null);
    addContributor(contributors, "Jan Blaha", "developper", "cz");
    addContributor(contributors, "Tureba", "developper", "brazil");
    addContributor(contributors, "hakvf", "tester", "france");
    addContributor(contributors, "Stefano \"Kismet\" Lenzi", "developper", "italian");
    jLabel5 = new JLabel(contributors.toString());
    jLabel5.setFont(MToolKit.defaultFont);
    jLabel5.setHorizontalAlignment(SwingConstants.LEFT);
    thanksPanelLeft.add(jLabel5);
    jLabel5 = new JLink("http://obsidiurne.free.fr", "morgil has designed the splash screen");
    jLabel5.setFont(MToolKit.defaultFont);
    thanksPanelLeft.add(jLabel5);
    thanksPanel.add(thanksPanelLeft);

    gameParamPanel.add(thanksPanel);

    thanksPanel = new JPanel();
    thanksPanel.setLayout(new BoxLayout(thanksPanel, BoxLayout.X_AXIS));
    thanksPanel.setMaximumSize(new Dimension(32767, 26));
    thanksPanel.setOpaque(false);
    JLabel blanklbl = new JLabel();
    blanklbl.setHorizontalAlignment(SwingConstants.RIGHT);
    blanklbl.setMaximumSize(new Dimension(100, 16));
    blanklbl.setMinimumSize(new Dimension(100, 16));
    blanklbl.setPreferredSize(new Dimension(100, 16));
    thanksPanel.add(blanklbl);

    jLabel5 = new JLink(
            "http://sourceforge.net/tracker/?func=add&group_id=" + IdConst.PROJECT_ID + "&atid=601043",
            LanguageManager.getString("joindev"));
    jLabel5.setFont(MToolKit.defaultFont);
    thanksPanel.add(jLabel5);
    gameParamPanel.add(thanksPanel);

    thanksPanel = new JPanel();
    thanksPanel.setLayout(new BoxLayout(thanksPanel, BoxLayout.X_AXIS));
    thanksPanel.setOpaque(false);
    jLabel5 = new JLabel(LanguageManager.getString("projecthome") + " : ");
    jLabel5.setFont(MToolKit.defaultFont);
    jLabel5.setHorizontalAlignment(SwingConstants.RIGHT);
    jLabel5.setMaximumSize(new Dimension(100, 16));
    jLabel5.setMinimumSize(new Dimension(100, 16));
    jLabel5.setPreferredSize(new Dimension(100, 16));
    thanksPanel.add(jLabel5);
    jLabel5 = new JLink(IdConst.MAIN_PAGE, IdConst.MAIN_PAGE);
    jLabel5.setFont(MToolKit.defaultFont);
    thanksPanel.add(jLabel5);
    gameParamPanel.add(thanksPanel);

    // forum francais
    thanksPanel = new JPanel();
    thanksPanel.setLayout(new BoxLayout(thanksPanel, BoxLayout.X_AXIS));
    thanksPanel.setOpaque(false);
    jLabel5 = new JLabel(LanguageManager.getString("othersites") + " : ");
    jLabel5.setFont(MToolKit.defaultFont);
    jLabel5.setHorizontalAlignment(SwingConstants.RIGHT);
    jLabel5.setMaximumSize(new Dimension(100, 16));
    jLabel5.setMinimumSize(new Dimension(100, 16));
    jLabel5.setPreferredSize(new Dimension(100, 16));
    thanksPanel.add(jLabel5);
    jLabel5 = new JLink("http://www.Firemox.fr.st", UIHelper.getIcon("mpfrsml.gif"), SwingConstants.LEFT);
    jLabel5.setToolTipText(LanguageManager.getString("frenchforum.tooltip"));
    thanksPanel.add(jLabel5);
    jLabel5 = new JLabel();
    jLabel5.setMaximumSize(new Dimension(1000, 16));
    thanksPanel.add(jLabel5);
    gameParamPanel.add(thanksPanel);

    JTextArea disclaimer = new JTextArea();
    disclaimer.setEditable(false);
    disclaimer.setLineWrap(true);
    disclaimer.setWrapStyleWord(true);
    disclaimer.setAutoscrolls(true);
    disclaimer.setTabSize(2);
    disclaimer.setFont(new Font("Arial", 0, 10));
    // Then try and read it locally
    BufferedReader inGPL = null;
    try {
        inGPL = new BufferedReader(new InputStreamReader(MToolKit.getResourceAsStream(IdConst.FILE_LICENSE)));
        disclaimer.read(inGPL, "");
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(inGPL);
    }
    JScrollPane disclaimerSPanel = new JScrollPane();
    disclaimerSPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    MToolKit.addOverlay(disclaimerSPanel);
    disclaimerSPanel.setViewportView(disclaimer);
    gameParamPanel.add(disclaimerSPanel);
}

From source file:JavaXWin.java

public void newFrame() {
    JInternalFrame jif = new JInternalFrame("Frame " + m_count, true, true, true, true);
    jif.setBounds(20 * (m_count % 10) + m_tencount * 80, 20 * (m_count % 10), 200, 200);

    JTextArea text = new JTextArea();
    JScrollPane scroller = new JScrollPane();
    scroller.getViewport().add(text);//www  . ja  v a  2 s . com
    try {
        FileReader fileStream = new FileReader("");
        text.read(fileStream, "JavaLinux.txt");
    } catch (Exception e) {
        text.setText("* Could not read JavaLinux.txt *");
    }
    jif.getContentPane().add(scroller);

    m_desktop.add(jif);
    try {
        jif.setSelected(true);
    } catch (PropertyVetoException pve) {
        System.out.println("Could not select " + jif.getTitle());
    }

    m_count++;
    if (m_count % 10 == 0) {
        if (m_tencount < 3)
            m_tencount++;
        else
            m_tencount = 0;
    }
}

From source file:org.olivier.ihm.FramePUMLCleanerControler.java

/**
 * Charge le fichier dans un Text Area//from  w  w  w.  ja  v a2s. c om
 *
 * @param filename Le fichier  charger
 */
private void readInputFile(String filename, JTextArea jTextAreaFichier) {
    final FileReader reader;
    try {
        reader = new FileReader(filename);
        final BufferedReader br = new BufferedReader(reader);
        jTextAreaFichier.read(br, null);
        br.close();
        jTextAreaFichier.requestFocus();
    } catch (FileNotFoundException ex) {
        LOGGER.log(Level.SEVERE, "FileNotFoundException", ex);
        JOptionPane.showMessageDialog(null, filename + " n'existe pas !", "Erreur",
                JOptionPane.WARNING_MESSAGE);
    } catch (IOException ex) {
        LOGGER.log(Level.SEVERE, "IOException", ex);
    }
}

From source file:pcgen.gui2.dialog.AboutDialog.java

/**
 * Construct the license panel. This panel shows the full
 * text of the license under which PCGen is distributed.
 *
 * @return The license panel.// w ww.  j a  va  2 s .  co m
 */
private JPanel buildLicensePanel() {
    JPanel lPanel = new JPanel();

    JScrollPane license = new JScrollPane();
    JTextArea lgplArea = new JTextArea();

    lPanel.setLayout(new BorderLayout());

    lgplArea.setEditable(false);

    InputStream lgpl = ClassLoader.getSystemResourceAsStream("LICENSE"); //$NON-NLS-1$

    if (lgpl != null) {
        try {
            lgplArea.read(new InputStreamReader(lgpl), "LICENSE"); //$NON-NLS-1$
        } catch (IOException ioe) {
            lgplArea.setText(LanguageBundle.getString("in_abt_license_read_err1")); //$NON-NLS-1$
        }
    } else {
        lgplArea.setText(LanguageBundle.getString("in_abt_license_read_err2")); //$NON-NLS-1$
    }

    license.setViewportView(lgplArea);
    lPanel.add(license, BorderLayout.CENTER);

    return lPanel;
}

From source file:updater.UpdaterGUI.java

@SuppressWarnings("resource")
public UpdaterGUI() {
    try {/*from   w  w  w.j a v  a 2  s . c  o m*/
        URL url1 = new URL(
                "https://raw.githubusercontent.com/kvsjxd/Droid-PC-Suite/master/.release-version.txt");
        ReadableByteChannel obj1 = Channels.newChannel(url1.openStream());
        FileOutputStream outputstream1 = new FileOutputStream(".release-version.txt");
        outputstream1.getChannel().transferFrom(obj1, 0, Long.MAX_VALUE);
        URL url2 = new URL(
                "https://raw.githubusercontent.com/kvsjxd/Droid-PC-Suite/master/.release-changelog.txt");
        ReadableByteChannel obj2 = Channels.newChannel(url2.openStream());
        FileOutputStream outputstream2 = new FileOutputStream(".release-changelog.txt");
        outputstream2.getChannel().transferFrom(obj2, 0, Long.MAX_VALUE);
        FileReader file = new FileReader(".release-version.txt");
        BufferedReader reader = new BufferedReader(file);
        String DownloadedString = reader.readLine();
        File file2 = new File(".release-version.txt");
        if (file2.exists() && !file2.isDirectory()) {
            file2.delete();
        }
        AvailableUpdate = Double.parseDouble(DownloadedString);
        InputStreamReader reader2 = new InputStreamReader(
                getClass().getResourceAsStream("/others/app-version.txt"));
        String tmp = IOUtils.toString(reader2);
        ApplicationVersion = Double.parseDouble(tmp);
    } catch (Exception e) {
        e.printStackTrace();
    }
    setIconImage(Toolkit.getDefaultToolkit().getImage(UpdaterGUI.class.getResource("/graphics/Icon.png")));
    setResizable(false);
    setType(Type.UTILITY);
    setTitle("Updater");
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 430, 415);
    contentPane = new JPanel();
    contentPane.setBackground(Color.WHITE);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel lblApplicationVersion = new JLabel("App Version: v" + ApplicationVersion);
    lblApplicationVersion.setBounds(12, 12, 222, 15);
    contentPane.add(lblApplicationVersion);

    JLabel lblUpdateVersion = new JLabel("Update Version: v" + AvailableUpdate);
    lblUpdateVersion.setBounds(12, 30, 222, 15);
    contentPane.add(lblUpdateVersion);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(0, 51, 422, 281);
    contentPane.add(scrollPane);

    JTextArea UpdateChangelogViewer = new JTextArea();
    scrollPane.setViewportView(UpdateChangelogViewer);

    JButton btnDownload = new JButton("Download");
    btnDownload.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFrame parentFrame = new JFrame();
            JFileChooser fileChooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Zip Files", "zip");
            fileChooser.setFileFilter(filter);
            fileChooser.setDialogTitle("Save as");
            int userSelection = fileChooser.showSaveDialog(parentFrame);
            if (userSelection == JFileChooser.APPROVE_OPTION) {
                File fileToSave = fileChooser.getSelectedFile();
                try {
                    URL url = new URL("https://github.com/kvsjxd/Droid-PC-Suite/releases/download/"
                            + AvailableUpdate + "/DPCS.v" + AvailableUpdate + ".Stable.zip");
                    ReadableByteChannel obj = Channels.newChannel(url.openStream());
                    FileOutputStream outputstream = new FileOutputStream(fileToSave.getAbsolutePath() + ".zip");
                    outputstream.getChannel().transferFrom(obj, 0, Long.MAX_VALUE);
                    JOptionPane.showMessageDialog(null,
                            "Download complete!\nPlease delete this version and extract the downloaded zip\nwhich is saved at "
                                    + fileToSave.getAbsolutePath() + ".zip");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });
    btnDownload.setBounds(140, 344, 117, 25);
    contentPane.add(btnDownload);
    try {
        FileReader reader3 = new FileReader(new File(".release-changelog.txt"));
        UpdateChangelogViewer.read(reader3, "");
        File file3 = new File(".release-changelog.txt");
        if (file3.exists() && !file3.isDirectory()) {
            file3.delete();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}