jtable question

hey all

i have a jtable that have more than one column....

i have a component called JHyperLinkedLabel...

my question is how can i make every column on each row have this custom component

below is the custom component that i need to add to every row on each first column...

please help

tahnks in advance

import javax.swing.*;

import java.awt.*;

import java.awt.event.MouseEvent;

import java.awt.event.MouseMotionListener;

/**

* @author tim yates

*/

publicclass JHyperlinklabelextends JLabelimplements MouseMotionListener{

/**

* Creates a new instance of JHyperlinklabel

*

* @param text

*/

public JHyperlinklabel(String text){

super("<html><b><u>" + text +"</u></b></html>");

this.setForeground(Color.blue);

this.addMouseMotionListener(this);

}

publicvoid mouseDragged(MouseEvent e){

}

/**

* This method is taken from inside the source of JLabel (in the inner AccessibleJLabel class)

*

* @return

*/

private Rectangle getTextRectangle(){

String text = getText();

Icon icon = (isEnabled()) ? getIcon() : getDisabledIcon();

if ((icon ==null) && (text ==null)){

returnnull;

}

Rectangle paintIconR =new Rectangle();

Rectangle paintTextR =new Rectangle();

Rectangle paintViewR =new Rectangle();

Insets paintViewInsets =new Insets(0, 0, 0, 0);

paintViewInsets = getInsets(paintViewInsets);

paintViewR.x = paintViewInsets.left;

paintViewR.y = paintViewInsets.top;

paintViewR.width = getWidth() - (paintViewInsets.left + paintViewInsets.right);

paintViewR.height = getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

Graphics g = getGraphics();

if (g ==null){

returnnull;

}

String clippedText = SwingUtilities.layoutCompoundLabel(

(JComponent) this,

g.getFontMetrics(),

text,

icon,

getVerticalAlignment(),

getHorizontalAlignment(),

getVerticalTextPosition(),

getHorizontalTextPosition(),

paintViewR,

paintIconR,

paintTextR,

getIconTextGap());

return paintTextR;

}

publicvoid mouseMoved(MouseEvent e){

if (getTextRectangle().contains(e.getPoint())){

this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

}else{

this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

}

}

}

[4275 byte] By [bif_fa] at [2007-11-27 3:54:15]
# 1

You don't add components to tables. A table just displays data using a renderer, not real components.

If you want to have a cell look like a HyperLink, then you will need to create a custom renderer and add a MouseListener to the table to handle the mouse clicks on the cell.

Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender]How to Use Tables[/url] for more information about renderers.

camickra at 2007-7-12 8:58:21 > top of Java-index,Desktop,Core GUI APIs...