Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying text in a JTable cell in response to MouseEvent

 
Steve Zeller
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic