Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7863165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:23:48+00:00 2026-06-02T23:23:48+00:00

I have a JTable where I display some string data formatted using html. I

  • 0

I have a JTable where I display some string data formatted using html. I need to show a tool tip based on the text under the mouse pointer

enter image description here

On mouse over “Line1” and “Line2” I need to show different tool tips. Is there any way to achieve this or do I have to use a custom renderer to render each line with a cell and show tool tip based on that ?

Here’s the sample code to create the table

package com.sample.table;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.*;

public class SampleTable {

private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("SampleTable");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.getContentPane().add(createTablePanel(), BorderLayout.CENTER);

    //Display the window.
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

public static JPanel createTablePanel(){
    JPanel tablePanel = new JPanel();

    JTable table = createTable();
    table.setFillsViewportHeight(true);
    table.setRowHeight(45);
    addListener(table);

    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setPreferredSize(new Dimension(300, 120));

    tablePanel.add(scrollPane);

    return tablePanel;
}

private static void addListener(JTable table) {
    table.addMouseMotionListener(new MouseMotionListener() {

        @Override
        public void mouseMoved(MouseEvent e) {
            if(e.getSource() instanceof JTable){
                JTable table = (JTable)e.getSource();

                table.setToolTipText("Some tooltip");
            }

        }

        @Override
        public void mouseDragged(MouseEvent e) {
            // do nothing

        }
    });

}

public static JTable createTable(){
    String[] columnNames = {"Column1", "Column2"};
    Object[][] data = {{"1", "<html>Line1<br/>Line2</html>"},
                        {"2", "<html>Line1<br/>Line2</html>"}};

    JTable table = new JTable(data, columnNames);

    return table;
}



public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:23:50+00:00Added an answer on June 2, 2026 at 11:23 pm

    Override the getToolTipText(MouseEvent) method of the component which your TableCellRenderer returns. If you are extending DefaultTableCellRenderer which extends JLabel and returns itself as renderer component, you can override it directly in your subclass.

    You should be able to determine over which line the mouse pointer is using MouseEvent#getPoint(). See JTextComponent#viewToModel or JTextArea#getLineOfOffset (if you are using a JTextArea for rendering instead of a JLabel).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTable that I want to use to display some data (a
I have tried using the code below to display ImageIcons in JTable. But when
Suppose you have a JTable and for each cell you want to display three
I have Java Desktop application that displays some information in a JTable that contains
Example now I have a main frame contains jtable display all the customer information,
I have a JTable which uses a custom TableModel to display a series of
I have data from a database loaded into a JTable through a custom table
i need some help with a sql query. I have a table called 'table1'
I am using a JScrollPane to display a JTable . I want the columns
I have a JTable using setAutoCreateRowSorter(true) and a RowSorterListener attached, per below, because I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.