Example usage for javax.swing JTextArea JTextArea

List of usage examples for javax.swing JTextArea JTextArea

Introduction

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

Prototype

public JTextArea(Document doc) 

Source Link

Document

Constructs a new JTextArea with the given document model, and defaults for all of the other arguments (null, 0, 0).

Usage

From source file:it.unibas.spicygui.vista.QueryTabbedPane.java

private void initArea(String xQuery) {
    textArea = new JTextArea(xQuery);
    textArea.setEditable(false);
    jScrollPane.setViewportView(textArea);
}

From source file:de.atomfrede.tools.evalutation.ui.ExceptionDialog.java

public JComponent createDetailsPanel() {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    exception.printStackTrace(pw);/*from  ww  w  .  j a v a  2 s  . c  o m*/
    JTextArea textArea = new JTextArea(sw.toString());
    // textArea.setRows(10);

    JLabel label = new JLabel("Details:");

    JPanel panel = new JPanel(new BorderLayout(6, 6));
    panel.add(new JScrollPane(textArea));
    panel.add(label, BorderLayout.BEFORE_FIRST_LINE);
    label.setLabelFor(textArea);
    panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));

    setSize((int) panel.getPreferredSize().getWidth() + 20, getHeight() + 95);
    setMinimumSize(getSize());
    setMaximumSize(new Dimension(getSize().width, getSize().height + 150));
    panel.setMaximumSize(new Dimension((int) getMaximumSize().getWidth(), 150));
    return panel;
}

From source file:net.sf.taverna.t2.renderers.SVGRenderer.java

@SuppressWarnings("serial")
public JComponent getComponent(Path path) throws RendererException {
    if (DataBundles.isValue(path) || DataBundles.isReference(path)) {
        long approximateSizeInBytes = 0;
        try {//from w ww  . j ava 2s .co m
            approximateSizeInBytes = RendererUtils.getSizeInBytes(path);
        } catch (Exception ex) {
            logger.error("Failed to get the size of the data", ex);
            return new JTextArea("Failed to get the size of the data (see error log for more details): \n"
                    + ex.getMessage());
        }

        if (approximateSizeInBytes > MEGABYTE) {
            int response = JOptionPane.showConfirmDialog(null, "Result is approximately "
                    + bytesToMeg(approximateSizeInBytes)
                    + " MB in size, there could be issues with rendering this inside Taverna\nDo you want to continue?",
                    "Render as SVG?", JOptionPane.YES_NO_OPTION);

            if (response != JOptionPane.YES_OPTION) {
                return new JTextArea(
                        "Rendering cancelled due to size of data. Try saving and viewing in an external application.");
            }
        }

        String resolve = null;
        try {
            // Resolve it as a string
            resolve = RendererUtils.getString(path);
        } catch (Exception e) {
            logger.error("Reference Service failed to render data as string", e);
            return new JTextArea(
                    "Reference Service failed to render data as string (see error log for more details): \n"
                            + e.getMessage());
        }

        final JSVGCanvas svgCanvas = new JSVGCanvas();
        File tmpFile = null;
        try {
            tmpFile = File.createTempFile("taverna", "svg");
            tmpFile.deleteOnExit();
            FileUtils.writeStringToFile(tmpFile, resolve, "utf8");
        } catch (IOException e) {
            logger.error("SVG Renderer: Failed to write the data to temporary file", e);
            return new JTextArea(
                    "Failed to write the data to temporary file (see error log for more details): \n"
                            + e.getMessage());
        }
        try {
            svgCanvas.setURI(tmpFile.toURI().toASCIIString());
        } catch (Exception e) {
            logger.error("Failed to create SVG renderer", e);
            return new JTextArea(
                    "Failed to create SVG renderer (see error log for more details): \n" + e.getMessage());
        }
        JPanel jp = new JPanel() {
            @Override
            protected void finalize() throws Throwable {
                svgCanvas.stopProcessing();
                super.finalize();
            }
        };
        jp.add(svgCanvas);
        return jp;
    } else {
        logger.error("Failed to obtain the data to render: data is not a value or reference");
        return new JTextArea("Failed to obtain the data to render: data is not a value or reference");
    }
}

From source file:es.uvigo.ei.sing.adops.views.TextFileViewer.java

public TextFileViewer(final File file) {
    super(new BorderLayout());

    this.file = file;

    // TEXT AREA/*from  w  w w .j  av a2 s  . c o m*/
    this.textArea = new JTextArea(TextFileViewer.loadFile(file));
    this.textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, this.textArea.getFont().getSize()));
    this.textArea.setLineWrap(true);
    this.textArea.setWrapStyleWord(true);
    this.textArea.setEditable(false);

    this.highlightPatiner = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);

    // OPTIONS PANEL
    final JPanel panelOptions = new JPanel(new BorderLayout());
    final JPanel panelOptionsEast = new JPanel(new FlowLayout());
    final JPanel panelOptionsWest = new JPanel(new FlowLayout());
    final JCheckBox chkLineWrap = new JCheckBox("Line wrap", true);
    final JButton btnChangeFont = new JButton("Change Font");

    final JLabel lblSearch = new JLabel("Search");
    this.txtSearch = new JTextField();
    this.chkRegularExpression = new JCheckBox("Reg. exp.", true);
    final JButton btnSearch = new JButton("Search");
    final JButton btnClear = new JButton("Clear");
    this.txtSearch.setColumns(12);
    // this.txtSearch.setOpaque(true);

    panelOptionsEast.add(btnChangeFont);
    panelOptionsEast.add(chkLineWrap);
    panelOptionsWest.add(lblSearch);
    panelOptionsWest.add(this.txtSearch);
    panelOptionsWest.add(this.chkRegularExpression);
    panelOptionsWest.add(btnSearch);
    panelOptionsWest.add(btnClear);

    if (FastaUtils.isFasta(file)) {
        panelOptionsWest.add(new JSeparator());

        final JButton btnExport = new JButton("Export...");

        panelOptionsWest.add(btnExport);

        btnExport.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    new ExportDialog(file).setVisible(true);
                } catch (Exception e1) {
                    JOptionPane.showMessageDialog(Workbench.getInstance().getMainFrame(),
                            "Error reading fasta file: " + e1.getMessage(), "Export Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        });
    }

    panelOptions.add(panelOptionsWest, BorderLayout.WEST);
    panelOptions.add(panelOptionsEast, BorderLayout.EAST);

    this.fontChooser = new JFontChooser();

    this.add(new JScrollPane(this.textArea), BorderLayout.CENTER);
    this.add(panelOptions, BorderLayout.NORTH);

    chkLineWrap.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            textArea.setLineWrap(chkLineWrap.isSelected());
        }
    });

    btnChangeFont.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            changeFont();
        }
    });

    this.textArea.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            TextFileViewer.this.wasModified = true;
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            TextFileViewer.this.wasModified = true;
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            TextFileViewer.this.wasModified = true;
        }
    });

    this.textArea.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            if (TextFileViewer.this.wasModified) {
                try {
                    FileUtils.write(TextFileViewer.this.file, TextFileViewer.this.textArea.getText());
                    TextFileViewer.this.wasModified = false;
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    });

    final ActionListener alSearch = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateSearch();
        }
    };
    txtSearch.addActionListener(alSearch);
    btnSearch.addActionListener(alSearch);

    btnClear.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            clearSearch();
        }
    });
}

From source file:mulavito.gui.components.LayerDataPanel.java

public LayerDataPanel(FloatingTabbedPane owner) {
    super("Layer Data", owner);

    textArea = new JTextArea(defaultText);
    textArea.setEditable(false);/* w  w w . j  a va2s . c  om*/
    textArea.setCaretPosition(0); // Scroll up the text area.
    JScrollPane textPane = new JScrollPane(textArea);

    add(textPane, BorderLayout.CENTER);

    // updates the data
    mouseListener = new MouseAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void mouseEntered(MouseEvent e) {
            if (e.getSource() instanceof LayerViewer<?, ?>) {
                LayerViewer<V, E> vv = (LayerViewer<V, E>) e.getSource();
                showData(vv.getLayer());
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            showData(null);
        }
    };

    // adds/removes focus listeners on layers
    graphPanelListener = new PropertyChangeListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("Viewers")) {
                if (evt.getOldValue() instanceof LayerViewer<?, ?> && evt.getNewValue() == null) {
                    // GraphPanel#removeLayer
                    ((LayerViewer<?, ?>) evt.getOldValue()).removeMouseListener(mouseListener);
                } else if (evt.getOldValue() instanceof List<?>) {
                    System.out.println("Replace");
                    for (LayerViewer<?, ?> vv : ((List<LayerViewer<?, ?>>) evt.getOldValue()))
                        vv.removeMouseListener(mouseListener);
                }

                if (evt.getNewValue() instanceof LayerViewer<?, ?> && evt.getOldValue() == null) {
                    // GraphPanel#addLayer
                    ((LayerViewer<?, ?>) evt.getNewValue()).addMouseListener(mouseListener);
                } else if (evt.getNewValue() instanceof List<?>) {
                    // New Layer List on start up
                    for (LayerViewer<?, ?> vv : ((List<LayerViewer<?, ?>>) evt.getNewValue()))
                        vv.addMouseListener(mouseListener);
                }

                showData(current);
            }
        }
    };
}

From source file:com.googlecode.logVisualizer.chart.SkillCastOnTurnsChartMouseEventListener.java

public void chartMouseClicked(final ChartMouseEvent e) {
    if (e.getEntity() instanceof CategoryItemEntity) {
        final CategoryItemEntity entity = (CategoryItemEntity) e.getEntity();
        final String skillName = (String) entity.getColumnKey();

        final StringBuilder str = new StringBuilder(250);
        if (logData.isDetailedLog())
            for (final SingleTurn st : logData.getTurnsSpent()) {
                if (st.isSkillCast(skillName))
                    str.append(st.getTurnNumber() + ": " + getCastedSkill(st, skillName).getAmount() + "\n");
            }/*from  w w  w  .  j a  v  a2s. c o  m*/
        else
            for (final TurnInterval ti : logData.getTurnIntervalsSpent())
                if (ti.isSkillCast(skillName))
                    str.append(ti.getStartTurn() + "-" + ti.getEndTurn() + ": "
                            + getCastedSkill(ti, skillName).getAmount() + "\n");

        final JScrollPane text = new JScrollPane(new JTextArea(str.toString()));
        text.setPreferredSize(new Dimension(500, 450));
        JOptionPane.showMessageDialog(null, text, "Turn numbers and amount of casts of " + skillName,
                JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:com.googlecode.logVisualizer.chart.TurnsSpentInLevelChartMouseEventListener.java

public void chartMouseClicked(final ChartMouseEvent e) {
    if (e.getEntity() instanceof CategoryItemEntity) {
        final CategoryItemEntity entity = (CategoryItemEntity) e.getEntity();
        final Matcher m = levelNumberExtractor.matcher((String) entity.getColumnKey());
        m.find();/* w  w  w .  ja v  a  2  s.c o m*/
        final int level = Integer.parseInt(m.group(1));

        final StringBuilder str = new StringBuilder(100);
        for (final TurnInterval ti : logData.getTurnIntervalsSpent()) {
            final int levelOnStart = logData.getCurrentLevel(ti.getStartTurn()).getLevelNumber();
            final int levelOnEnd = logData.getCurrentLevel(ti.getEndTurn()).getLevelNumber();

            if (levelOnStart > level)
                break;

            if (levelOnStart == level || levelOnEnd == level)
                str.append(ti + "\n");
        }

        final JScrollPane text = new JScrollPane(new JTextArea(str.toString()));
        text.setPreferredSize(new Dimension(500, 450));
        JOptionPane.showMessageDialog(null, text, "Areas visited during level " + level,
                JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:org.esa.s1tbx.insar.rcp.toolviews.insar_statistics.StatESDMeasure.java

public Component createPanel() {

    // Add the series to your data set
    dataset = new XYSeriesCollection();

    // Generate the graph
    chart = ChartFactory.createXYLineChart(TITLE, // Title
            XAXIS_LABEL, // x-axis Label
            YAXIS_LABEL, // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );/*from  ww w . ja v  a2  s  . c o  m*/

    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    panel = new JPanel(new BorderLayout());
    textarea = new JTextArea(EmptyMsg);
    panel.add(textarea, BorderLayout.NORTH);
    panel.add(chartPanel, BorderLayout.CENTER);
    setVisible(false);

    return panel;
}

From source file:it.unibas.spicygui.vista.TGDTabbedPane.java

private void initArea(String tgd) {
    textArea = new JTextArea(tgd);
    textArea.setEditable(false);
    jScrollPane.setViewportView(textArea);
}

From source file:eu.lp0.cursus.ui.AboutDialog.java

private void initialise() {
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setTitle(Messages.getString("about.title", Constants.APP_DESC)); //$NON-NLS-1$
    DefaultUnitConverter duc = DefaultUnitConverter.getInstance();

    FormLayout layout = new FormLayout("2dlu, pref, fill:pref:grow, max(30dlu;pref), 2dlu", //$NON-NLS-1$
            "2dlu, max(15dlu;pref), 2dlu, max(15dlu;pref), 2dlu, fill:max(100dlu;pref):grow, 2dlu, max(16dlu;pref), 2dlu"); //$NON-NLS-1$
    getContentPane().setLayout(layout);/*from  ww w . java 2 s. c om*/

    JLabel lblName = new JLabel(Constants.APP_NAME + ": " + Messages.getString("about.description")); //$NON-NLS-1$ //$NON-NLS-2$
    getContentPane().add(lblName, "2, 2, 3, 1"); //$NON-NLS-1$

    getContentPane().add(new LinkJButton(Constants.APP_URL), "2, 4"); //$NON-NLS-1$

    JScrollPane scrCopying = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    getContentPane().add(scrCopying, "2, 6, 3, 1"); //$NON-NLS-1$

    JTextArea txtCopying = new JTextArea(loadResources("COPYRIGHT", "LICENCE")); //$NON-NLS-1$ //$NON-NLS-2$
    txtCopying.setFont(Font.decode(Font.MONOSPACED));
    txtCopying.setEditable(false);
    scrCopying.setViewportView(txtCopying);
    scrCopying.setPreferredSize(
            new Dimension(scrCopying.getPreferredSize().width, duc.dialogUnitYAsPixel(100, scrCopying)));

    Action actClose = new CloseDialogAction(this);
    JButton btnClose = new JButton(actClose);
    getContentPane().add(btnClose, "4, 8"); //$NON-NLS-1$

    getRootPane().setDefaultButton(btnClose);
    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CloseDialogAction.class.getName());
    getRootPane().getActionMap().put(CloseDialogAction.class.getName(), actClose);

    pack();
    setMinimumSize(getSize());
    setSize(getSize().width, getSize().height * 3 / 2);
    btnClose.requestFocusInWindow();
}