Search in sources :

Example 66 with JTextArea

use of javax.swing.JTextArea in project jdk8u_jdk by JetBrains.

the class LWTextAreaPeer method insert.

@Override
public void insert(final String text, final int pos) {
    final ScrollableJTextArea pane = getDelegate();
    synchronized (getDelegateLock()) {
        final JTextArea area = pane.getView();
        final boolean doScroll = pos >= area.getDocument().getLength() && area.getDocument().getLength() != 0;
        area.insert(text, pos);
        revalidate();
        if (doScroll) {
            final JScrollBar vbar = pane.getVerticalScrollBar();
            if (vbar != null) {
                vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount());
            }
        }
    }
    repaintPeer();
}
Also used : JTextArea(javax.swing.JTextArea) JScrollBar(javax.swing.JScrollBar)

Example 67 with JTextArea

use of javax.swing.JTextArea in project jdk8u_jdk by JetBrains.

the class LWTextAreaPeer method setScrollBarVisibility.

private void setScrollBarVisibility(final int visibility) {
    final ScrollableJTextArea pane = getDelegate();
    final JTextArea view = pane.getView();
    view.setLineWrap(false);
    switch(visibility) {
        case TextArea.SCROLLBARS_NONE:
            pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
            view.setLineWrap(true);
            break;
        case TextArea.SCROLLBARS_VERTICAL_ONLY:
            pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            view.setLineWrap(true);
            break;
        case TextArea.SCROLLBARS_HORIZONTAL_ONLY:
            pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
            pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
            break;
        default:
            pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
            pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            break;
    }
}
Also used : JTextArea(javax.swing.JTextArea)

Example 68 with JTextArea

use of javax.swing.JTextArea in project JMRI by JMRI.

the class RouteEditTableModel method setComment.

private void setComment(RouteLocation rl) {
    // Create comment panel
    final JDialog dialog = new JDialog();
    dialog.setLayout(new BorderLayout());
    dialog.setTitle(Bundle.getMessage("Comment") + " " + rl.getName());
    final JTextArea commentTextArea = new JTextArea(5, 100);
    JScrollPane commentScroller = new JScrollPane(commentTextArea);
    dialog.add(commentScroller, BorderLayout.CENTER);
    commentTextArea.setText(rl.getComment());
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
    dialog.add(buttonPane, BorderLayout.SOUTH);
    JButton okayButton = new JButton(Bundle.getMessage("ButtonOK"));
    okayButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            rl.setComment(commentTextArea.getText());
            dialog.dispose();
            return;
        }
    });
    buttonPane.add(okayButton);
    JButton cancelButton = new JButton(Bundle.getMessage("ButtonCancel"));
    cancelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            dialog.dispose();
            return;
        }
    });
    buttonPane.add(cancelButton);
    dialog.setModal(true);
    dialog.pack();
    dialog.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) FlowLayout(java.awt.FlowLayout) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JDialog(javax.swing.JDialog)

Example 69 with JTextArea

use of javax.swing.JTextArea in project JMRI by JMRI.

the class FileHistoryAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    JFrame frame = new JmriJFrame() {
    };
    // JmriJFrame to ensure fits on screen
    JTextArea pane = new JTextArea();
    // add a little space at top
    pane.append("\n");
    pane.setEditable(false);
    JScrollPane scroll = new JScrollPane(pane);
    frame.getContentPane().add(scroll);
    FileHistory r = InstanceManager.getNullableDefault(FileHistory.class);
    if (r == null) {
        pane.append("<No History Found>\n");
    } else {
        pane.append(r.toString());
    }
    // add a little space at bottom
    pane.append("\n");
    frame.pack();
    // start scrolled to top
    JScrollBar b = scroll.getVerticalScrollBar();
    b.setValue(b.getMaximum());
    // show
    frame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) JmriJFrame(jmri.util.JmriJFrame) JFrame(javax.swing.JFrame) JmriJFrame(jmri.util.JmriJFrame) FileHistory(jmri.jmrit.revhistory.FileHistory) JScrollBar(javax.swing.JScrollBar)

Example 70 with JTextArea

use of javax.swing.JTextArea in project processdash by dtuma.

the class ExceptionDialog method show.

/**
     * Display a JOptionPane with information about a Throwable.
     * 
     * @param parentComponent
     *            the owner of the JOptionPane; can be null
     * @param title
     *            the title to display for the JOptionPane
     * @param contents
     *            the items to display within the JOptionPane. Each item can be
     *            <ul>
     *            <li>A Throwable, which will be displayed in the dialog as a
     *            text area showing the stack trace. (Note: if a copy link is
     *            present, the contents array <b>must</b> contain at least one
     *            Throwable. If no copy link is present, the contents array can
     *            contain zero or more Throwables.)</li>
     * 
     *            <li>A string containing a hyperlink in &lt;a&gt;some
     *            text&lt;/a&gt; format. The embedded text will become a
     *            hyperlink to copy the stack trace to the clipboard.</li>
     * 
     *            <li>A regular String or any other object, which will be passed
     *            along to the JOptionPane unchanged.</li>
     * 
     *            <li>A Collection or array of the above items</li>
     *            </ul>
     * 
     * @throws IllegalArgumentException
     *             if the contents parameter contained a copy link but did not
     *             contain any Throwables
     */
public static void show(Component parentComponent, String title, Object... contents) throws IllegalArgumentException {
    JTextArea textArea = new JTextArea();
    textArea.setEditable(false);
    textArea.setLineWrap(false);
    textArea.setFont(textArea.getFont().deriveFont(textArea.getFont().getSize2D() * 0.8f));
    CopyToClipboardHandler copyHandler = new CopyToClipboardHandler(textArea);
    textArea.addFocusListener(copyHandler);
    ShowSubdialogHandler subdialogHandler = null;
    JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(400, 100));
    List items = new ArrayList();
    boolean sawThrowable = false;
    boolean sawCopyLink = false;
    for (Object o : flattenContents(contents)) {
        if (o instanceof Throwable) {
            if (sawThrowable)
                textArea.append(DELIMITER);
            else if (subdialogHandler == null)
                items.add(scrollPane);
            textArea.append(getStackTrace((Throwable) o));
            textArea.setCaretPosition(0);
            sawThrowable = true;
        } else if (o == USE_SUBDIALOG) {
            subdialogHandler = new ShowSubdialogHandler(title, scrollPane);
        } else if (isCopyLink(o)) {
            JLinkLabel errorTraceLabel = new JLinkLabel((String) o);
            errorTraceLabel.addActionListener(//
            subdialogHandler == null ? copyHandler : subdialogHandler);
            items.add(errorTraceLabel);
            sawCopyLink = true;
        } else if (o != null) {
            items.add(o);
        }
    }
    if (sawCopyLink && !sawThrowable)
        throw new IllegalArgumentException("A Throwable must be included in the argument list");
    if (subdialogHandler != null && sawThrowable && !sawCopyLink)
        throw new IllegalArgumentException("A copy link must be included in the argument list");
    JOptionPane.showMessageDialog(parentComponent, items.toArray(), title, JOptionPane.ERROR_MESSAGE);
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Dimension(java.awt.Dimension)

Aggregations

JTextArea (javax.swing.JTextArea)182 JScrollPane (javax.swing.JScrollPane)104 JPanel (javax.swing.JPanel)79 BorderLayout (java.awt.BorderLayout)60 JButton (javax.swing.JButton)59 JLabel (javax.swing.JLabel)59 Dimension (java.awt.Dimension)36 JTextField (javax.swing.JTextField)35 JFrame (javax.swing.JFrame)33 ActionEvent (java.awt.event.ActionEvent)26 Font (java.awt.Font)24 GridBagLayout (java.awt.GridBagLayout)23 GridBagConstraints (java.awt.GridBagConstraints)22 Insets (java.awt.Insets)22 ActionListener (java.awt.event.ActionListener)21 FlowLayout (java.awt.FlowLayout)20 Color (java.awt.Color)18 JCheckBox (javax.swing.JCheckBox)18 JSplitPane (javax.swing.JSplitPane)16 EmptyBorder (javax.swing.border.EmptyBorder)16