Class PopupTextDialog

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class PopupTextDialog extends JDialog
A dialog that can be used to view or edit text in a resizable window. Originally used by LongTextField as the "pop-out" editor, but useful enough to be reusable elsewhere.

This dialog allows resize, and will remember the last size that it was set to, as long as the application is running. This size is not persisted, so it is lost when the application exits.

Since:
swing-extras 2.5
Author:
scorbo2
See Also:
  • Field Details

    • MIN_WIDTH

      protected static final int MIN_WIDTH
      See Also:
    • MIN_HEIGHT

      protected static final int MIN_HEIGHT
      See Also:
    • lastWidth

      protected static int lastWidth
    • lastHeight

      protected static int lastHeight
    • ownerWindow

      protected final Window ownerWindow
    • textArea

      protected JTextArea textArea
    • copyButton

      protected JButton copyButton
    • cancelButton

      protected JButton cancelButton
    • wasOkayed

      protected boolean wasOkayed
  • Constructor Details

    • PopupTextDialog

      public PopupTextDialog(Window owner, String title, String text, boolean isModal)
  • Method Details

    • getTextArea

      public JTextArea getTextArea()
      Allow direct access to the JTextArea for custom manipulation. For example, you want a certain font size, color, face, or background color.
    • wasOkayed

      public boolean wasOkayed()
      Returns true if the user clicked the OK button, false if the dialog closed any other way.
    • getText

      public String getText()
    • setText

      public void setText(String newText)
      Replaces the current text contents with the specified contents.
    • isReadOnly

      public boolean isReadOnly()
    • setReadOnly

      public void setReadOnly(boolean isReadOnly)
      Allows or disallows editing in the text field. In read-only mode, the Cancel button is hidden as it serves no purpose.
    • isClipboardEnabled

      public boolean isClipboardEnabled()
    • setClipboardEnabled

      public void setClipboardEnabled(boolean isEnabled)
      Shows or hides the "copy to clipboard" button.
    • copyToClipboard

      public void copyToClipboard()
      Copies the current text contents to the clipboard.
    • setSize

      public void setSize(Dimension dim)
      Overridden here so that when the dialog size is programmatically changed, we re-center ourselves over our owner window.
      Overrides:
      setSize in class Window
    • buttonHandler

      protected void buttonHandler(boolean isOk)
    • updateCancelButtonVisibility

      protected void updateCancelButtonVisibility()
      Updates the visibility of the Cancel button based on whether the dialog is in read-only mode. In read-only mode, the Cancel button is hidden since editing is not possible.
    • initComponents

      protected void initComponents(String text)
    • buildTextArea

      protected JScrollPane buildTextArea(String text)
      Creates a plain jane JTextArea with word wrap enabled. You can extend this class and override this method if you want something fancier. Or, if you just want to customize the text area a little, you can use getTextArea in this class and tweak it as you need to (custom font or whatever).
    • buildButtonPanel

      protected JPanel buildButtonPanel()
      Invoked internally to create the button panel at the bottom with the "copy to clipboard", cancel, and OK buttons.