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..
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.getSour ce();
Point pt = e.getPoint();
if ( theTable.columnAtPoint(pt) == yourSpecificColumn ) {
int row = theTable.rowAtPoint(pt);
// get the data for that row and open the link
}
}
});
yourTable.addMouseListener
public void mouseClicked(MouseEvent e) {
JTable theTable = (JTable)MouseEvent.getSour
Point pt = e.getPoint();
if ( theTable.columnAtPoint(pt)
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
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?
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yep..that sounds like a good idea..i'll give it a shot...thanks
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