public static JPanel getPanel() {
    FormLayout lm =
        new FormLayout(
            "fill:pref, 2dlu, fill:pref, 0dlu, fill:min:grow, 0dlu, fill:pref, 2dlu, fill:pref",
            "");
    DefaultFormBuilder builder = new DefaultFormBuilder(lm);
    builder.setBorder(new EmptyBorder(0, 0, 0, 0));

    final JLabel fontSizeLabel = new JLabel();
    fontSizeLabel.setText(
        SubstanceLookAndFeel.getFontPolicy()
                .getFontSet("Substance", null)
                .getControlFont()
                .getSize()
            + " pt.");
    builder.append(fontSizeLabel);
    // fontSizeLabel.add(Box.createHorizontalStrut(5));

    Icon zoomOutIcon = Check.configure(new View_zoom_out(), 16);
    JLabel zoomOutLabel = new JLabel(zoomOutIcon);
    builder.append(zoomOutLabel);

    final JSlider fontSizeSlider = new JSlider(0, 10, 0);
    fontSizeSlider.setFocusable(false);
    // fontSizeSlider.setOpaque(false);
    fontSizeSlider.setToolTipText(
        "Controls the global font set size. Resets Substance as the current LAF.");
    fontSizeSlider.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            // if the value is adjusting - ignore. This is done
            // to make CPU usage better.
            if (!fontSizeSlider.getModel().getValueIsAdjusting()) {
              final int newValue = fontSizeSlider.getValue();
              SwingUtilities.invokeLater(
                  new Runnable() {
                    public void run() {
                      SubstanceLookAndFeel.setFontPolicy(null);
                      final FontSet substanceCoreFontSet =
                          SubstanceLookAndFeel.getFontPolicy().getFontSet("Substance", null);
                      FontPolicy newFontPolicy =
                          new FontPolicy() {
                            public FontSet getFontSet(String lafName, UIDefaults table) {
                              return new WrapperFontSet(substanceCoreFontSet, newValue);
                            }
                          };

                      SubstanceLookAndFeel.setFontPolicy(newFontPolicy);

                      fontSizeLabel.setText(
                          SubstanceLookAndFeel.getFontPolicy()
                                  .getFontSet("Substance", null)
                                  .getControlFont()
                                  .getSize()
                              + " pt.");
                    }
                  });
            }
          }
        });
    builder.append(fontSizeSlider);

    Icon zoomInIcon = Check.configure(new View_zoom_in(), 16);
    JLabel zoomInLabel = new JLabel(zoomInIcon);
    builder.append(zoomInLabel);

    JButton tahoma = new JButton("Tahoma 11");
    tahoma.putClientProperty(SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE);
    tahoma.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    SubstanceLookAndFeel.setFontPolicy(null);
                    FontPolicy newFontPolicy =
                        new FontPolicy() {
                          public FontSet getFontSet(String lafName, UIDefaults table) {
                            return new Tahoma11FontSet();
                          }
                        };

                    SubstanceLookAndFeel.setFontPolicy(newFontPolicy);

                    fontSizeLabel.setText(
                        SubstanceLookAndFeel.getFontPolicy()
                                .getFontSet("Substance", null)
                                .getControlFont()
                                .getSize()
                            + " pt.");
                  }
                });
          }
        });
    builder.append(tahoma);

    JPanel result = builder.getPanel();
    // result.setOpaque(false);
    return result;
  }
예제 #2
0
  /**
   * Returns the control panel for testing dialogs.
   *
   * @param mainFrame The main test frame.
   * @return Control panel for testing dialogs.
   */
  public static JPanel getDialogControlPanel(final JFrame mainFrame) {
    FormLayout lm = new FormLayout("right:pref, 4dlu, fill:pref:grow", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(lm);

    builder.appendSeparator("Core choosers");
    JButton bfo = new JButton("Open dialog", Check.getIcon("JFileChooserColor16"));
    bfo.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JFileChooser jfc = new JFileChooser();
                    jfc.showOpenDialog(mainFrame);
                  }
                });
          }
        });
    builder.append("File chooser", bfo);

    JButton bfs = new JButton("Save dialog", Check.getIcon("JFileChooserColor16"));
    bfs.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JFileChooser jfc = new JFileChooser();
                    jfc.showSaveDialog(mainFrame);
                  }
                });
          }
        });
    builder.append("", bfs);

    JButton bc = new JButton("Open", Check.getIcon("JColorChooserColor16"));
    bc.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    Color color =
                        JColorChooser.showDialog(
                            mainFrame, "Color chooser", new Color(23, 45, 200));
                    if (color != null) {
                      Check.out("Chosen " + color.toString());
                    }
                  }
                });
          }
        });
    builder.append("Color chooser", bc);

    JButton bcWindow = new JButton("open in window");
    bcWindow.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    final Window window = new Window(mainFrame);
                    window.setLayout(new BorderLayout());
                    window.add(new JColorChooser());
                    window.pack();
                    window.setLocationRelativeTo(null);
                    window.setVisible(true);
                    Timer timerDispose =
                        new Timer(
                            5000,
                            new ActionListener() {
                              @Override
                              public void actionPerformed(ActionEvent e) {
                                window.dispose();
                              }
                            });
                    timerDispose.setRepeats(false);
                    timerDispose.start();
                  }
                });
          }
        });
    builder.append("", bcWindow);

    builder.appendSeparator("Option panes");

    JButton bop = new JButton("Show");
    bop.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane pane = new JOptionPane("Sample option pane");
                    JDialog dialog = pane.createDialog(mainFrame, "Sample title");
                    dialog.setVisible(true);
                    dialog.dispose();
                  }
                });
          }
        });
    builder.append("Plain", bop);

    JButton bopi = new JButton("Show", Check.getIcon("22/dialog-information"));
    bopi.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane.showMessageDialog(
                        mainFrame,
                        "Sample info message",
                        "Sample title",
                        JOptionPane.INFORMATION_MESSAGE);
                  }
                });
          }
        });
    builder.append("Info", bopi);

    JButton bope = new JButton("Show", Check.getIcon("22/dialog-error"));
    bope.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane.showMessageDialog(
                        mainFrame,
                        "Sample error message",
                        "Sample title",
                        JOptionPane.ERROR_MESSAGE);
                  }
                });
          }
        });
    builder.append("Error", bope);

    JButton bopw = new JButton("Show", Check.getIcon("22/dialog-warning"));
    bopw.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane.showMessageDialog(
                        mainFrame,
                        "Sample warning message",
                        "Sample title",
                        JOptionPane.WARNING_MESSAGE);
                  }
                });
          }
        });
    builder.append("Warning", bopw);

    JButton bopq = new JButton("Show", Check.getIcon("22/help-browser"));
    bopq.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane.showMessageDialog(
                        mainFrame,
                        "Sample question message",
                        "Sample title",
                        JOptionPane.QUESTION_MESSAGE);
                  }
                });
          }
        });
    builder.append("Question", bopq);

    JButton bopc = new JButton("Show");
    bopc.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JOptionPane.showOptionDialog(
                        mainFrame,
                        new JPanel(),
                        "Option",
                        JOptionPane.OK_CANCEL_OPTION,
                        JOptionPane.PLAIN_MESSAGE,
                        null,
                        null,
                        null);
                  }
                });
          }
        });
    builder.append("Custom", bopc);

    JButton buttonOptionPaneSimpleInput = new JButton("Show");
    buttonOptionPaneSimpleInput.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JDialog dialog = new JDialog(mainFrame, "Sample dialog", true);
                    dialog.setSize(400, 300);
                    dialog.setLocationRelativeTo(mainFrame);
                    dialog.setLayout(new BorderLayout());
                    JDesktopPane panel = new JDesktopPane();
                    dialog.add(panel, BorderLayout.CENTER);
                    JOptionPane.showInputDialog(
                        panel, "Sample Question Message?", "Default Answer");
                    dialog.dispose();
                  }
                });
          }
        });
    builder.append("Simple input", buttonOptionPaneSimpleInput);

    JButton buttonOptionPaneComplexInput = new JButton("Show");
    buttonOptionPaneComplexInput.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JDialog dialog = new JDialog(mainFrame, "Sample dialog", true);
                    dialog.setSize(400, 300);
                    dialog.setLocationRelativeTo(mainFrame);
                    dialog.setLayout(new BorderLayout());
                    JDesktopPane panel = new JDesktopPane();
                    dialog.add(panel, BorderLayout.CENTER);
                    // dialog.setVisible(true);
                    String optionChoices[] = new String[] {"entry1", "entry2", "entry3", "entry4"};
                    JOptionPane.showInputDialog(
                        panel,
                        "Sample Question Message?",
                        "Title Goes Here",
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        optionChoices,
                        "entry1");
                    dialog.dispose();
                  }
                });
          }
        });
    builder.append("Complex input", buttonOptionPaneComplexInput);

    JButton buttonOptionPaneInternalInput = new JButton("Show");
    buttonOptionPaneInternalInput.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JDialog dialog = new JDialog(mainFrame, "Sample dialog", true);
                    dialog.setSize(400, 300);
                    dialog.setLocationRelativeTo(mainFrame);
                    dialog.setLayout(new BorderLayout());
                    JDesktopPane panel = new JDesktopPane();
                    dialog.add(panel, BorderLayout.CENTER);
                    // dialog.setVisible(true);
                    JOptionPane.showInternalInputDialog(
                        panel,
                        "Sample info message",
                        "Sample title",
                        JOptionPane.INFORMATION_MESSAGE);
                    dialog.dispose();
                  }
                });
          }
        });
    builder.append("Internal input", buttonOptionPaneInternalInput);

    builder.appendSeparator("Default buttons");

    JButton openDisposable = new JButton("Open");
    openDisposable.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    if (disposableDialog != null) {
                      disposableDialog.setVisible(true);
                      return;
                    }
                    disposableDialog = new JDialog();
                    disposableDialog.setTitle("Disposable");

                    JTree tree = new JTree();
                    JScrollPane jsp =
                        new JScrollPane(
                            tree,
                            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                    jsp.putClientProperty(
                        LafWidget.COMPONENT_PREVIEW_PAINTER, new DefaultPreviewPainter());

                    disposableDialog.setLayout(new BorderLayout());
                    disposableDialog.add(jsp, BorderLayout.CENTER);

                    disposableDialog.setSize(200, 100);
                    disposableDialog.setLocationRelativeTo(null);
                    disposableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                    disposableDialog.setVisible(true);
                  }
                });
          }
        });
    builder.append("Disposable dialog", openDisposable);

    JButton launchFrameDialogWithIcon = new JButton("Open");
    launchFrameDialogWithIcon.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    SimpleDialog sd = new SimpleDialog();
                    if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
                      sd.setIconImage(
                          SubstanceLogo.getLogoImage(
                              SubstanceLookAndFeel.getCurrentSkin(sd.getRootPane())
                                  .getColorScheme(
                                      DecorationAreaType.PRIMARY_TITLE_PANE,
                                      ColorSchemeAssociationKind.FILL,
                                      ComponentState.ENABLED)));
                    }
                    sd.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
                    sd.setModal(false);
                    sd.pack();
                    sd.setLocationRelativeTo(null);
                    sd.setVisible(true);
                    sd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                  }
                });
          }
        });
    builder.append("Dialog with icon", launchFrameDialogWithIcon);

    JButton bd = new JButton("Open");
    bd.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    SimpleDialog sd = new SimpleDialog();
                    sd.setModal(false);
                    sd.pack();
                    sd.setLocationRelativeTo(null);
                    sd.setVisible(true);
                    simpleDialog = sd;
                  }
                });
          }
        });
    builder.append("Open a dialog", bd);

    JButton bcd = new JButton("Close");
    bcd.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    if (simpleDialog != null) {
                      simpleDialog.removeAll();
                      simpleDialog.dispose();
                      ReferenceQueue<JButton> weakQueue = new ReferenceQueue<JButton>();
                      WeakReference<JButton> weakRef =
                          new WeakReference<JButton>(simpleDialog.b1, weakQueue);
                      weakRef.enqueue();
                      simpleDialog.b1 = null;
                      simpleDialog = null;
                      System.gc();
                      // Wait until the weak reference is on the queue and
                      // remove
                      // it
                      Check.out("Waiting to remove");
                      try {
                        Reference<?> ref = weakQueue.remove();
                        ref.clear();
                      } catch (InterruptedException ie) {
                        ie.printStackTrace();
                        return;
                      }
                      Check.out("Removed");
                    }
                  }
                });
          }
        });
    builder.append("Close the dialog", bcd);

    JButton buttonDialogCloseOnEsc = new JButton("Show");
    buttonDialogCloseOnEsc.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    final JDialog dialog = new JDialog((Frame) null, "Click ESC to dispose");
                    dialog.setSize(200, 200);
                    dialog.setLayout(new BorderLayout());

                    JPanel myContentPane = new JPanel();
                    myContentPane.setLayout(new BorderLayout());
                    dialog.setContentPane(myContentPane);

                    JTabbedPane tabs = new JTabbedPane();
                    JPanel tab1 = new JPanel(new FlowLayout());
                    tab1.add(new JLabel("test"));
                    JTextField tab1TextField = new JTextField("some text");
                    tab1TextField.putClientProperty(
                        LafWidget.TEXT_FLIP_SELECT_ON_ESCAPE, Boolean.TRUE);
                    tab1.add(tab1TextField);
                    tabs.addTab("Foo", tab1);
                    JPanel tab2 = new JPanel(new FlowLayout());
                    tab2.add(new JButton("Test"));
                    tabs.addTab("Bar", tab2);
                    dialog.add(tabs, BorderLayout.CENTER);

                    dialog.add(new JLabel("Press Esc to close dialog"), BorderLayout.NORTH);

                    // connect "Esc" key with disposing the dialog
                    String actionName = "VK_ESCAPE";
                    Action action =
                        new AbstractAction(actionName) {
                          @Override
                          public void actionPerformed(ActionEvent e) {
                            dialog.dispose();
                          }
                        };
                    myContentPane.getActionMap().put(actionName, action);
                    myContentPane
                        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
                        .put(
                            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0),
                            actionName);

                    dialog.setLocationRelativeTo(null);
                    dialog.setVisible(true);
                  }
                });
          }
        });
    builder.append("Dialog with ESC close", buttonDialogCloseOnEsc);

    JButton buttonDialogUndecorated = new JButton("Show");
    buttonDialogUndecorated.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    final JDialog dialog = new JDialog((Frame) null, "");
                    dialog.setSize(200, 200);
                    dialog.setUndecorated(true);
                    dialog.setLayout(new BorderLayout());

                    JPanel myContentPane = new JPanel();
                    myContentPane.setLayout(new BorderLayout());
                    dialog.setContentPane(myContentPane);

                    dialog.add(new JLabel("Press Esc to close dialog"), BorderLayout.NORTH);

                    // connect "Esc" key with "System.exit(0)"
                    String actionName = "VK_ESCAPE";
                    Action action =
                        new AbstractAction(actionName) {
                          @Override
                          public void actionPerformed(ActionEvent e) {
                            dialog.dispose();
                          }
                        };
                    myContentPane.getActionMap().put(actionName, action);
                    myContentPane
                        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
                        .put(
                            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0),
                            actionName);

                    dialog.setLocationRelativeTo(null);
                    dialog.setVisible(true);
                  }
                });
          }
        });
    builder.append("Undecorated dialog", buttonDialogUndecorated);

    builder.appendSeparator("Miscellaneous");

    JButton customSkinFrame = new JButton("Show");
    customSkinFrame.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JFrame testFrame = new SampleFrame();
                    testFrame
                        .getRootPane()
                        .putClientProperty(
                            SubstanceLookAndFeel.SKIN_PROPERTY, new NebulaBrickWallSkin());
                    SwingUtilities.updateComponentTreeUI(testFrame.getRootPane());
                    testFrame.setSize(315, 245);
                    testFrame.setLocationRelativeTo(mainFrame);
                    testFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    testFrame.setVisible(true);
                  }
                });
          }
        });
    builder.append("Nebula brick wall frame", customSkinFrame);

    JButton btf = new JButton("Show");
    btf.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JFrame testFrame = new JFrame("test1");
                    testFrame.setSize(262, 100);
                    testFrame.setLocationRelativeTo(mainFrame);
                    testFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    testFrame.setVisible(true);
                  }
                });
          }
        });
    builder.append("Regular frame", btf);

    JButton btfU = new JButton("Show");
    btfU.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JFrame.setDefaultLookAndFeelDecorated(false);
                    JDialog.setDefaultLookAndFeelDecorated(false);

                    JFrame testFrame = new JFrame("test undecorated");
                    // testFrame.setUndecorated(true);

                    testFrame.setSize(262, 100);
                    testFrame.setLocation(400, 400);
                    testFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    testFrame.setVisible(true);

                    JFrame.setDefaultLookAndFeelDecorated(true);
                    JDialog.setDefaultLookAndFeelDecorated(true);
                  }
                });
          }
        });
    builder.append("Undecorated frame", btfU);

    JButton bcp = new JButton("Open");
    bcp.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {

                    JFrame colorFrame = new JFrame();
                    final ColorPanel cp1 = new ColorPanel("default");
                    final ColorPanel cp2 = new ColorPanel("green");
                    cp2.setBackground(Color.green);
                    final ColorPanel cp3 = new ColorPanel("red");
                    cp3.setBackground(Color.red);
                    final ColorPanel cp4 = new ColorPanel("black");
                    cp4.setBackground(Color.black);
                    // cp2.setBackground(Color.GREEN);
                    colorFrame.setLayout(
                        new LayoutManager() {
                          @Override
                          public void addLayoutComponent(String name, Component comp) {}

                          @Override
                          public void layoutContainer(Container parent) {
                            int h = parent.getHeight() / 2;
                            int w = parent.getWidth() / 2;
                            cp1.setBounds(0, 0, w, h);
                            cp2.setBounds(0, h, w, parent.getHeight() - h);
                            cp3.setBounds(w, 0, w, h + 1);
                            cp4.setBounds(w, h + 1, w, parent.getHeight() - h);
                          }

                          @Override
                          public Dimension minimumLayoutSize(Container parent) {
                            return preferredLayoutSize(parent);
                          }

                          @Override
                          public Dimension preferredLayoutSize(Container parent) {
                            return new Dimension(100, 100);
                          }

                          @Override
                          public void removeLayoutComponent(Component comp) {}
                        });
                    colorFrame.add(cp1);
                    colorFrame.add(cp2);
                    colorFrame.add(cp3);
                    colorFrame.add(cp4);

                    colorFrame.setSize(400, 399);
                    colorFrame.setLocation(300, 300);
                    colorFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    colorFrame.setVisible(true);
                  }
                });
          }
        });
    builder.append("Color panels", bcp);

    JButton paneDialog = new JButton("Open");
    paneDialog.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    JDialog dialog = new JDialog(mainFrame, true);
                    dialog.setTitle("Test text pane in scroll pane");
                    JTextPane textPane = new JTextPane();
                    String contents = "";
                    for (int i = 0; i < 100; i++)
                      contents +=
                          "This is sample line " + i + " and a lot of other irrelevant text\n";
                    textPane.replaceSelection(contents);

                    JScrollPane scroll = new JScrollPane(textPane);
                    JPanel panel = new JPanel();
                    panel.setLayout(new BorderLayout());
                    panel.add(scroll, BorderLayout.CENTER);

                    dialog.setLayout(new BorderLayout());
                    dialog.add(panel, BorderLayout.CENTER);
                    dialog.setSize(400, 400);
                    dialog.setLocation(400, 200);
                    dialog.setVisible(true);
                  }
                });
          }
        });
    builder.append("Text pane dialog", paneDialog);

    return builder.getPanel();
  }