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();
}
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;
}
}
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);
}
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);
}
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 <a>some
* text</a> 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);
}
Aggregations