Link to home
Start Free TrialLog in
Avatar of trance12
trance12

asked on

jtable column link

is it posssible to have a column in a  jtable as a link ..i need the link to open another applet...i have the jtable dispalying data from a table (multiple columns)..i need one of the columns to be a link and when the cursor is placed over the link, the color of the cell changes to red..

Avatar of zzynx
zzynx
Flag of Belgium image

>> is it posssible to have a column in a  jtable as a link
Not automatically.
But if you add a MouseListener to the JTable you can become what you want.

>> when the cursor is placed over the link, the color of the cell changes to red
Possible using the combination of (the same) MouseListener and a TableCellRenderer
Not easily achieved sorry

>> if you add a MouseListener to the JTable you can become what you want.

yourTable.addMouseListener( new MouseAdapter() {
     public void mouseClicked(MouseEvent e)  {
          JTable theTable = (JTable)MouseEvent.getSource();
          Point pt = e.getPoint();
          if ( theTable.columnAtPoint(pt) == yourSpecificColumn ) {
              int row = theTable.rowAtPoint(pt);
              // get the data for that row and open the link
          }
     }
});
You'll need to do more than that to get the link to display
Avatar of trance12
trance12

ASKER

can i ask if there is a better tool than to display data from  a table..i know jlist only displays one column..is there anything else other than a jtable and a jlist?
not for displaying tabular data, what is it you are trying to achieve?

i have data from a table ..5 columns..i'm using a jtable to select and display the data..one of the columns in the jtable needs to be a hyperlink..when the user clicks on that column data, it opens a a diferent applet
You can achieve that using a table, you'll just need to implement your own renderer, and the mouse over and mouse click behaviour yourself.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yep..that sounds like a good idea..i'll give it a shot...thanks