Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2005

Tip: Looking for answers? Try searching our database.

jtable and tooltips

Thread view: 
Boris Woeste - 21 Mar 2005 21:47 GMT
hi

i want to use tooltips with a jtable. I have successfully tried with
setToolTipText in the method getTableCellRendererComponent() in the
TableCellRenderer. But on every repaint of the jtable the method
getTableCellRenderer() sets all the tooltip texts. This is bad because
the tooltip gets its text from some objects from a remote server which
is not very fast. So far.
The idea is to use a mouse listener on the jtable. On double-click my
own tooltip should appear.
I tried something like this (no result):

public class mlTable extends MouseAdapter {
   public void mouseClicked(MouseEvent e) {
     int column = tTable.columnAtPoint(e.getPoint());
     int row = tTable.rowAtPoint(e.getPoint());

     if(e.getButton()==MouseEvent.BUTTON1 && e.getClickCount()==2) {
         JToolTip tp = new JToolTip;
    tp.setTipText(my_server_object.getText());
    tp.setComponenent( ((myTable)e.getSource()).getComponentAt(
            e.getPoint()) .... );

    tp.setVisible(true);
        }
    }
}

Beside where is the difference between setTipText(String) and
setToolTipText(String) ?

Does my idea work ? Any ideas ?

Boris
Christian Kaufhold - 22 Mar 2005 18:12 GMT
> i want to use tooltips with a jtable. I have successfully tried with
> setToolTipText in the method getTableCellRendererComponent() in the
> TableCellRenderer. But on every repaint of the jtable the method
> getTableCellRenderer() sets all the tooltip texts. This is bad because
> the tooltip gets its text from some objects from a remote server which
> is not very fast. So far.

You can just override JTable.getToolTipText(MouseEvent) and only look
up the tooltip there instead of using the default behaviour of trying
to pick the renderer's tool tip text.

> The idea is to use a mouse listener on the jtable. On double-click my
> own tooltip should appear.
> I tried something like this (no result):

What does "no result" mean? Please post compilable code next time.

> public class mlTable extends MouseAdapter {
>    public void mouseClicked(MouseEvent e) {
[quoted text clipped - 6 lines]
>        tp.setComponenent( ((myTable)e.getSource()).getComponentAt(
>                        e.getPoint()) .... );

Eh, why not "tp.setComponent(tTable)"?

>        tp.setVisible(true);

Use Popup/PopupFactory to show the tooltip.

>         }
>     }
> }
>
> Beside where is the difference between setTipText(String) and
> setToolTipText(String) ?

setTipText sets the text the JToolTip displays. setToolTipText sets the
text that a (default) tooltip for the component you set it on displays.

Christian


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.