• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying text in a JTable cell in response to MouseEvent

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic