Created
          March 8, 2013 15:06 
        
      - 
      
 - 
        
Save wytten/5117035 to your computer and use it in GitHub Desktop.  
    Groovy Swing Hyperlinks
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import groovy.swing.SwingBuilder | |
| import java.awt.* | |
| import javax.swing.* | |
| import javax.swing.event.* | |
| SwingBuilder swing = new SwingBuilder() | |
| def panel = { | |
| JEditorPane editorPane = swing.editorPane() | |
| editorPane.setContentType("text/html") | |
| editorPane.setText("Do you prefer <a href='http://google.com/'>Google</a> or <a href='http://bing.com/'>Bing</a>?") | |
| editorPane.setEditable(false); | |
| editorPane.setOpaque(false); | |
| editorPane.addHyperlinkListener(new HyperlinkListener() { | |
| public void hyperlinkUpdate(HyperlinkEvent hle) { | |
| if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) { | |
| Desktop.getDesktop().browse(hle.getURL().toURI()); | |
| } | |
| } | |
| }); | |
| } | |
| swing.edt { | |
| frame(title:'TestHyperlink', size:[400, 150], defaultCloseOperation:JFrame.EXIT_ON_CLOSE, show:true) { panel() } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment