List of usage examples for javax.swing JTextPane viewToModel
@Deprecated(since = "9") public int viewToModel(Point pt)
From source file:Main.java
private static AttributeSet getAttributes(MouseEvent e) { JTextPane text = (JTextPane) e.getSource(); Point mouseLocation = new Point(e.getX(), e.getY()); int pos = text.viewToModel(mouseLocation); if (pos >= 0) { try {//from w w w . j a va 2s . c o m Rectangle rect = text.modelToView(pos); int lowerCorner = rect.y + rect.height; if (e.getX() < rect.x && e.getY() < lowerCorner && pos > 0) { pos--; } } catch (BadLocationException ex) { ex.printStackTrace(); } StyledDocument doc = text.getStyledDocument(); Element element = doc.getCharacterElement(pos); return element.getAttributes(); } return null; }