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 7979585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:48:53+00:00 2026-06-04T09:48:53+00:00

I want to display a text above a JTable cell when someone is editing

  • 0

I want to display a text above a JTable cell when someone is editing the cell. The text is pretty much the same as a tooltip with the exception, that the text should only be displayed when editing a cell and the text should stay until the editing is finished.

How could I achieve such a behaviour?

What I have tried so far is to override the getCellEditor method of JTable but that will only set the standard tooltip, but I need to display the text permanently for the time of the editing.

@Override
public TableCellEditor getCellEditor(int row, int column) {
    TableCellEditor editor = super.getCellEditor(row, column);
    Component component = editor.getTableCellEditorComponent(this, getValueAt(row, column), isCellSelected(row, column), row, column);
    if(component instanceof JTextField) {
        JTextField textfield = (JTextField) component;
        textfield.setToolTipText("tooltip");
    }
    return editor;
}
  • 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-04T09:48:55+00:00Added an answer on June 4, 2026 at 9:48 am

    Another option would be to also add a JLabel (or any component) when you start editing a cell. Whenever it stops, you remove the component.

    Because you want the tooltip/label to appear above the edited cell, it requires a little trick for the first row.

    Here is an example showing what I mean:

    import java.awt.Container;
    import java.awt.Point;
    import java.util.EventObject;
    
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.SwingUtilities;
    import javax.swing.event.ChangeEvent;
    import javax.swing.table.DefaultTableModel;
    
    public class TestTable {
    
        public JFrame f;
        private JLabel tooltip;
        private MyTable table;
    
        public class MyTable extends JTable {
    
            @Override
            public boolean editCellAt(int row, int column, EventObject e) {
                boolean editCellAt = super.editCellAt(row, column, e);
                if (editCellAt) {
                    Point editedCellLocation = getCellRect(getEditingRow(), getEditingColumn(), true).getLocation();
                    if (tooltip != null) {
                        removeTooltip();
                    }
                    tooltip = new JLabel("Hello some nice tooltip");
                    tooltip.setOpaque(true);
                    tooltip.setSize(tooltip.getPreferredSize());
                    if (getEditingRow() == 0) {
                        tooltip.setLocation(editedCellLocation.x, getTableHeader().getHeight() - tooltip.getHeight());
                        getTableHeader().add(tooltip);
                    } else {
                        tooltip.setLocation(editedCellLocation.x, editedCellLocation.y - tooltip.getHeight());
                        add(tooltip);
                    }
                    ((JComponent) tooltip.getParent()).repaint(tooltip.getBounds());
                }
                return editCellAt;
            }
    
            @Override
            public void editingStopped(ChangeEvent e) {
                super.editingStopped(e);
                removeTooltip();
            }
    
            protected void removeTooltip() {
                if (tooltip != null) {
                    Container parent = tooltip.getParent();
                    parent.remove(tooltip);
                    ((JComponent) parent).repaint(tooltip.getBounds());
                    tooltip = null;
                }
            }
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new TestTable().initUI();
                }
            });
        }
    
        protected void initUI() {
            table = new MyTable();
            table.setModel(new TestTableModel());
            f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(300, 300);
            f.setLocationRelativeTo(null);
            f.add(new JScrollPane(table));
            f.setVisible(true);
        }
    
        public class TestTableModel extends DefaultTableModel {
    
            public TestTableModel() {
                super(new String[] { "DATA" }, 3);
                setValueAt(Double.valueOf(-0.1), 0, 0);
                setValueAt(Double.valueOf(+0.1), 1, 0);
                setValueAt(Double.valueOf(0), 2, 0);
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display div above image so that div's top is aligned with
I have the password field on page. I want to display text Enter password
I want to display some text on twitter/facebook when a link is clicked on
I want to display some text for a few seconds and then quit my
In my code,I want to display TextView text name as Toast message. I do
In my XAML file I want to display this text which contains double and
I'm making a game and in the menu I want to display the text
I want to display svn revision number to a text file I am getting
I want to display a very large text file but want to break it
I want to display a mask in a text field. How can I do

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.