Example usage for javax.swing JEditorPane setBounds

List of usage examples for javax.swing JEditorPane setBounds

Introduction

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

Prototype

public void setBounds(Rectangle r) 

Source Link

Document

Moves and resizes this component to conform to the new bounding rectangle r .

Usage

From source file:Main.java

private Element getHyperlinkElement(MouseEvent event) {
    Point p = event.getPoint();/*from w  w  w . j  a va 2s.c o  m*/
    int selRow = tree.getRowForLocation(p.x, p.y);
    TreeCellRenderer r = tree.getCellRenderer();
    if (selRow == -1 || r == null) {
        return null;
    }
    TreePath path = tree.getPathForRow(selRow);
    Object lastPath = path.getLastPathComponent();
    Component rComponent = r.getTreeCellRendererComponent(tree, lastPath, tree.isRowSelected(selRow),
            tree.isExpanded(selRow), tree.getModel().isLeaf(lastPath), selRow, true);

    if (rComponent instanceof JEditorPane == false) {
        return null;
    }
    Rectangle pathBounds = tree.getPathBounds(path);
    JEditorPane editor = (JEditorPane) rComponent;
    editor.setBounds(tree.getRowBounds(selRow));
    p.translate(-pathBounds.x, -pathBounds.y);
    int pos = editor.getUI().viewToModel(editor, p);
    if (pos >= 0 && editor.getDocument() instanceof HTMLDocument) {
        HTMLDocument hdoc = (HTMLDocument) editor.getDocument();
        Element elem = hdoc.getCharacterElement(pos);
        if (elem.getAttributes().getAttribute(HTML.Tag.A) != null) {
            return elem;
        }
    }
    return null;
}