File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Displaying text  in a JTable cell in response to MouseEvent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Displaying text  in a JTable cell in response to MouseEvent" Watch "Displaying text  in a JTable cell in response to MouseEvent" New topic
Author

Displaying text in a JTable cell in response to MouseEvent

Steve Zeller
Greenhorn

Joined: Jan 31, 2001
Posts: 2
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
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
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Displaying text in a JTable cell in response to MouseEvent
 
Similar Threads
JTable
JTable
JTable "..."
JTable
JTable ........