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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:00:05+00:00 2026-05-27T23:00:05+00:00

I have this situation, where I would like to display a number in figures.

  • 0

I have this situation, where I would like to display a number in figures. The number will be entered onto a Jtextfield and I would like the tooltip to display the amount in figures. The problem is, the tooltip displays the older data.

I have written some code to show you the issue:

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class Test
{
 public static void main(String[] args) {
    final JFrame frame=new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setPreferredSize(new Dimension(400,100));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JTextField tf=new JTextField(30);
    frame.add(tf);
    frame.add(new JTextField(30));

    tf.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            tf.setToolTipText(tf.getText());
        }

        @Override
        public void focusGained(FocusEvent e) {
            tf.setToolTipText(tf.getText());
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            frame.pack();
            frame.setVisible(true);
        }
    });
 }
}

Let’s take this situation, the user is typing number onto the first textfield. The text cursor is still on the same textfield. When the user now moves the mouse pointer over the first textfield, the tooltip is still displaying the old text.
Now when you shift the focus to the second textfield, the first textfield’s data gets committed so the tooltip also refreshes.

Now how do I display the tooltip on the text that is still not committed in a textfield?

  • 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-05-27T23:00:06+00:00Added an answer on May 27, 2026 at 11:00 pm

    If you want to update the tooltips each time the user types something, you should add a DocumentListener to the Document of your JTextField, which can be retrieved using the JTextField#getDocument.

    The Swing tutorial has an example of such a DocumentListener

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

Sidebar

Related Questions

I have had several situations when i would like to do that. This could
I am curious how others would handle this situation. I have a domain layer
I have this situation where I want to display a list of Administration objects
Here's my situation. I have a sliding jquery menu like this: http://tympanus.net/codrops/2011/07/03/sliding-background-image-menu . The
I have this situation: $(#button).toggle(function(){ $(#window).animate({top:'0%'},1000); },function(){ $(#window).animate({top:'-100%'},1000); }); but I need change it
I have this situation: http://jsfiddle.net/bRDgK/3/ In this situation I have a modal dialog with
I have this situation: { float foo[10]; for (int i = 0; i <
We have this situation: Window Keyboard ^ ^ | / ApplicationWindow so class Window
I have this situation: interface MessageListener { void onMessageReceipt(Message message); } class MessageReceiver {
I have this situation: There are a login page with a login form (form

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.