Java Code Examples for javax.swing.JTextPane#setHighlighter()
The following examples show how to use
javax.swing.JTextPane#setHighlighter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OurAntiAlias.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Constructs an antialias-capable JTextPane with a DefaultHighlighter * associated with it. * * @param attributes - see {@link edu.mit.csail.sdg.alloy4.OurUtil#make * OurUtil.make(component, attributes...)} */ public static JTextPane pane(Function<MouseEvent,String> tooltip, Object... attributes) { JTextPane ans = new JTextPane() { static final long serialVersionUID = 0; @Override public void paint(Graphics gr) { if (antiAlias && gr instanceof Graphics2D) { ((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } super.paint(gr); } @Override public String getToolTipText(MouseEvent event) { if (tooltip != null) { return tooltip.apply(event); } return super.getToolTipText(event); } }; if (tooltip != null) ToolTipManager.sharedInstance().registerComponent(ans); OurUtil.make(ans, attributes); ans.setHighlighter(new DefaultHighlighter()); map.put(ans, Boolean.TRUE); return ans; }
Example 2
Source File: EditorCurrentLineHighlighter.java From SikuliX1 with MIT License | 4 votes |
public EditorCurrentLineHighlighter(JTextPane textPane, Color highlightColor) { Color c = highlightColor != null ? highlightColor : DEFAULT_COLOR; MyHighlighter h = new MyHighlighter(); textPane.setHighlighter(h); painter = new DefaultHighlighter.DefaultHighlightPainter(c); }
Example 3
Source File: ClipboardFrame.java From opt4j with MIT License | 4 votes |
/** * Constructs a {@link ClipboardFrame}. * * @param content * the content as a string */ public ClipboardFrame(final String content) { final JTextPane text = new JTextPane() { private static final long serialVersionUID = 1L; @Override public void processMouseEvent(MouseEvent me) { switch (me.getID()) { case MouseEvent.MOUSE_CLICKED: switch (me.getButton()) { case MouseEvent.BUTTON1: StringSelection stringSelection = new StringSelection(content); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, ClipboardFrame.this); break; default: break; } ClipboardFrame.this.dispose(); break; default: break; } } }; this.addMouseListener(new MouseAdapter() { @Override public void mouseExited(MouseEvent e) { ClipboardFrame.this.dispose(); } }); text.setCaretColor(Color.WHITE); text.setEditable(false); text.setHighlighter(null); text.setBorder(BorderFactory.createLineBorder(Color.WHITE, 4)); final StyledDocument doc = text.getStyledDocument(); try { doc.insertString(doc.getLength(), content, null); doc.remove(doc.getLength() - 1, 1); } catch (BadLocationException e1) { e1.printStackTrace(); } JPanel panel = new JPanel(new BorderLayout()); panel.add(text); panel.add(BorderLayout.SOUTH, new JLabel(" left-click: copy to clipboard")); panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); add(panel); setUndecorated(true); Point2D p = MouseInfo.getPointerInfo().getLocation(); setLocation((int) p.getX() - 8, (int) p.getY() - 8); }