CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2005
    Posts
    2

    Arrow How to show hyperlink in cell of JTable?

    Hi All,

    I want to show hyper link in cell of JTable . Clicking on it should display the content related to that hyper-link in browser. Thus, I have two task: one is let say for example I want to show image name "xyz.jpg" in table cell as a hyper link data. Second thing is when i click on link it should go to the URL let say http://myserver/xyz.jpg and open this image in browser.

    Any help regarding this will be appreciated.

    Thanx and Regards,

    Premal Panchal

  2. #2
    Join Date
    Sep 2004
    Posts
    15

    Re: How to show hyperlink in cell of JTable?

    Try sth like this:

    Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    class Test extends JFrame 
    {
       public static void main(String[]args)
       {
          new Test();
       }
       public Test()
       {
          Container cp = getContentPane();
          cp.setLayout(new FlowLayout());
          final JTextField tf = new JTextField("http://java.sun.com", 20);
          JLabel adress = new JLabel("Adress:");
          JLabel label = new JLabel("Just click it!");
          label.setBorder(BorderFactory.createLineBorder(Color.blue));
          label.addMouseListener(new MouseAdapter()
          {
             public void mouseClicked(MouseEvent e)
             {
                try
                {
                   Runtime.getRuntime().exec("c:/Program Files/Internet Explorer/iexplore " + tf.getText());
                }
                catch(java.io.IOException exc)
                {
                   System.out.println(exc.toString());
                }
             }
          });
          cp.add(adress);
          cp.add(tf);
          cp.add(label);
          pack();
          show();
       }
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



HTML5 Development Center

Click Here to Expand Forum to Full Width