Displaying text in a JTable cell in response to MouseEvent
Steve Zeller
Greenhorn
Joined: Jan 31, 2001
Posts: 2
posted
0
I'm looking for a code sample that displays the entire text in a JTable cell when the String is greater than the visible area of the cell and the mouse is passed over the given cell. Something similar to a tool tip. Thanks for any help you can provide.
java whizkid
Greenhorn
Joined: Aug 08, 2001
Posts: 1
posted
0
Originally posted by Steve Zeller: I'm looking for a code sample that displays the entire text in a JTable cell when the String is greater than the visible area of the cell and the mouse is passed over the given cell. Something similar to a tool tip. Thanks for any help you can provide.
**************** Me too have similar problem. Did you find the solution? Can you share the code if you know? thanks, whizkid
Sandeep Jain
Ranch Hand
Joined: Oct 25, 2000
Posts: 124
posted
0
Hello I have tried for ur requirement ,however I could not do that perfectly. Just check the code if it is useful to u .import javax.swing.*; import javax.swing.table.*; import java.awt.event.*; public class TableToolTip extends JFrame implements MouseListener,MouseMotionListener { DefaultTableModel model; JTable table; Object Rows[][]={{"sandy","26262626262626226262626262626262626262626262626","M.B.A"},{"jain","22","D.B.A"},{"sandeep","21","M.C.A"}}; Object Cols[]={"Name","Age","Education"}; String text=""; public TableToolTip() { model=new DefaultTableModel(Rows,Cols); table=new JTable(model); table.addMouseListener(this); table.addMouseMotionListener(this); this.getContentPane().add(table); } public static void main(String args[]) { TableToolTip tip=new TableToolTip(); tip.setSize(200,200); tip.setVisible(true); } public void mouseClicked(MouseEvent me) { int row=table.getSelectedRow(); int col=table.getSelectedColumn(); text=(String)table.getValueAt(row,col); table.setToolTipText(text); table.updateUI(); } public void mouseEntered(MouseEvent me){} public void mouseExited(MouseEvent me) { } public void mousePressed(MouseEvent me){} public void mouseReleased(MouseEvent me) { table.setToolTipText(text); } public void mouseDragged(MouseEvent me) {} public void mouseMoved(MouseEvent me) { } }
------------------ Try and Try Till u succeed Sandeep Jain
Try and Try Till u succeed<br /> <br />Sandeep Jain