HyperlinkListener

Questions on using RSyntaxTextArea should go here.

Moderator: robert

HyperlinkListener

Postby majo » Fri Aug 22, 2014 8:29 am

Hi Robert,

It´s possible use hyperlink lisener in RSTA whenI set XML style?

Because I implemt lisener and try use it, but when i type www.google.com and want click ... it still common text
majo
 
Posts: 10
Joined: Sun Jul 27, 2014 7:53 pm

Re: HyperlinkListener

Postby robert » Fri Aug 22, 2014 12:39 pm

Are you ctrl+clicking (or cmd+clicking on the Mac)? Ctrl/Cmd is the default modifier key to make links clickable. You change it by calling textArea.setLinkScanningMask(int).
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: HyperlinkListener

Postby majo » Fri Aug 22, 2014 9:52 pm

I use ctrl+clicking ...and try set textArea.setLinkScanningMask(InputEvent.CTRL_DOWN_MASK);
and it´s still not working
look at screen, please:
[IMG=http://www.image-share.com/upload/2668/207.png]

here is my test code:
Code: Select all
public class MyTextArea extends JFrame implements HyperlinkListener {

    public MyTextArea()  {
        JPanel cp = new JPanel(new BorderLayout());
        RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
        textArea.setCodeFoldingEnabled(true);
        textArea.setSyntaxEditingStyle("text/xml");
        RTextScrollPane sp = new RTextScrollPane(textArea);
        cp.add(sp);
        textArea.addHyperlinkListener(this);
        textArea.setLinkScanningMask(InputEvent.CTRL_DOWN_MASK);
        textArea.setHyperlinksEnabled(true);
        setContentPane(cp);
        setTitle("Demo");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        pack();
        setLocationRelativeTo(null);

    }

    /**
     * Test Component
     * @param args
     */
    public static void main(String[] args) {
        // Start all Swing applications on the EDT.
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new MyTextArea().setVisible(true);
            }
        });
    }

    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
        HyperlinkEvent.EventType type = e.getEventType();
        final URL url = e.getURL();
        if (type == HyperlinkEvent.EventType.ENTERED) {
            System.out.println("URL: " + url);
        } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
            System.out.println("Activated");
        }
    }
}
majo
 
Posts: 10
Joined: Sun Jul 27, 2014 7:53 pm

Re: HyperlinkListener

Postby robert » Sat Aug 23, 2014 2:54 am

Only hyperlinks in comments are automatically made clickable. In theory you can use a custom LinkGenerator to cause non-comment tokens to be made clickable (when hovered over and Ctrl is pressed), but I believe that only works for tokens, not arbitrary regions of text, so you might not be able to make your entire URL visually appear as a clickable link with this approach (just the word the mouse is over).
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 4 guests

cron