• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to display HyperLink Data in JTable column

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I have to display HyperLink Data in Jtable column... and that HyperLink is a URL after clicking that HyperLink data should be displayed..

still i couldn't get how can i display HyperLink in JTable column....

any one having any idea regarding this problem...

Thanks & Regards

Vaibhav
 
author
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds simple but it isn't. First a little JTable 101. Each cell in a JTable isn't a component. It is a block on the screen that is painted. Think of it more like an image. The JTable looks up a cell renderer based on the cell location, object type in the cell, etc and then uses it to paint the area. The default cell render is based off a JLabel. Since there is no component, you can't add a mouse listener or track click events to that label.

When you click on a cell the table goes into "edit" mode. A cell editor is created and displayed in the area the cell previous occupied. This is an acutal component that you can manipulate if you want.

Now back to your case. I'm guessing you want your links to appear as html style links. Since the table uses a render that extends JLabel (which supports html) you can feed it text like this:

<html><b><a href="">bold</a></b></html>

However, I wouldn't recommend altering the data in your model just to effect display. Instead I would create a custom cell renderer which accomplishes this effect and set it on the table. You could either wrap your text in the HTML or manually set font color and style properties on the renderer to mimic html.

Now even if you were to include the url in the html you still can't click on it. There is no component in the table. You don't really want to go into edit mode when clicking on a url. You just want to open that link. To accomplish this you would add a mouse listener to the table itself. When you receive a click event, you would then programatically determine which cell it was over, go back to your model and get the url, and finally use other Java API calls to open that url.

A quick Google search will reveal examples of creating a cell renderer, using a mouse listener, and opening a url if you need more information.

Scott Delap
Desktop Java Live
ClientJava.com
 
vaibhav agarwal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for Solution...

but still i could not exect... can you please send some code.....

>You just want to open that link...

Exactly I want only it bother about how so please give me some code related to this topic

Thanks & Regards
Vaibhav
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vaibhav agarwal:
Exactly I want only it bother about how so please give me some code related to this topic

Thanks & Regards
Vaibhav



That's really not what we are here to do. Like Scott said, Google turns up a ton of code examples related to your issue. Not only that but you can search this very forum for code samples.

Here is a quick rundown of how javaranch works. You write some code, it doesn't work, we help you figure it out. We also realize that sometimes a simple code snippit sends you in the right direction, however, you haven't shown any willingness to figure any of this out on your own.

We love helping people, but we love helping people that try even more.

To get you started though Sun has a wonderful tutorial on JTables and it even shows you how to write your very own cell renderer.
 
reply
    Bookmark Topic Watch Topic
  • New Topic