Example usage for javax.swing JEditorPane scrollRectToVisible

List of usage examples for javax.swing JEditorPane scrollRectToVisible

Introduction

In this page you can find the example usage for javax.swing JEditorPane scrollRectToVisible.

Prototype

public void scrollRectToVisible(Rectangle aRect) 

Source Link

Document

Forwards the scrollRectToVisible() message to the JComponent's parent.

Usage

From source file:tvbrowser.ui.settings.channel.ChannelGroupInfoDialog.java

/**
 * Create the GUI/* w  ww . j  a  va 2  s  .  c om*/
 */
private void initGui() {
    UiUtilities.registerForClosing(this);
    JPanel panel = (JPanel) getContentPane();
    panel.setBorder(Borders.DLU4_BORDER);
    panel.setLayout(new FormLayout("fill:default:grow, default", "fill:default:grow, 3dlu, default"));

    CellConstraints cc = new CellConstraints();

    final JEditorPane infoPanel = new JEditorPane();

    infoPanel.setEditorKit(new ExtendedHTMLEditorKit());

    ExtendedHTMLDocument doc = (ExtendedHTMLDocument) infoPanel.getDocument();

    infoPanel.setEditable(false);
    infoPanel.setText(generateHtml(doc));

    infoPanel.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                URL url = evt.getURL();
                if (url != null) {
                    Launch.openURL(url.toString());
                }
            }
        }
    });

    final JScrollPane scrollPane = new JScrollPane(infoPanel);
    panel.add(scrollPane, cc.xyw(1, 1, 2));

    JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK));

    ok.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            infoPanel.scrollRectToVisible(new Rectangle(0, 0));
        }
    });

    panel.add(ok, cc.xy(2, 3));

    setSize(500, 350);
}