List of usage examples for javax.swing JTextArea setComponentPopupMenu
@BeanProperty(preferred = true, description = "Popup to show") public void setComponentPopupMenu(JPopupMenu popup)
JPopupMenu
for this JComponent
. From source file:com.clank.launcher.swing.SwingHelper.java
/** * Show a message dialog using// w w w. ja v a 2 s . c o m * {@link javax.swing.JOptionPane#showMessageDialog(java.awt.Component, Object, String, int)}. * * <p>The dialog will be shown from the Event Dispatch Thread, regardless of the * thread it is called from. In either case, the method will block until the * user has closed the dialog (or dialog creation fails for whatever reason).</p> * * @param parentComponent the frame from which the dialog is displayed, otherwise * null to use the default frame * @param message the message to display * @param title the title string for the dialog * @param messageType see {@link javax.swing.JOptionPane#showMessageDialog(java.awt.Component, Object, String, int)} * for available message types */ public static void showMessageDialog(final Component parentComponent, @NonNull final String message, @NonNull final String title, final String detailsText, final int messageType) { if (SwingUtilities.isEventDispatchThread()) { // To force the label to wrap, convert the message to broken HTML String htmlMessage = "<html><div style=\"width: 250px\">" + htmlEscape(message); JPanel panel = new JPanel(new BorderLayout(0, detailsText != null ? 20 : 0)); // Add the main message panel.add(new JLabel(htmlMessage), BorderLayout.NORTH); // Add the extra details if (detailsText != null) { JTextArea textArea = new JTextArea(_("errors.reportErrorPreface") + detailsText); JLabel tempLabel = new JLabel(); textArea.setFont(tempLabel.getFont()); textArea.setBackground(tempLabel.getBackground()); textArea.setTabSize(2); textArea.setEditable(false); textArea.setComponentPopupMenu(TextFieldPopupMenu.INSTANCE); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setPreferredSize(new Dimension(350, 120)); panel.add(scrollPane, BorderLayout.CENTER); } JOptionPane.showMessageDialog(parentComponent, panel, title, messageType); } else { // Call method again from the Event Dispatch Thread try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { showMessageDialog(parentComponent, message, title, detailsText, messageType); } }); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } }