简体   繁体   中英

Is there a way to show a popup like a “cloud” when you passed your mouse over a textfield in Java?

I'm looking for a way to display a baloon tip when i mouse-over a textfield in Java, for example to guide the user in the way to put some specific data: ID: 0-0000-000 or something like that...

Is there a way to do that, other than jOptionPane?

I'm guessing you're looking for a way to add a tooltip ? Try this:

// A textfield with tooltip that provides help text
JTextField textfield = new JTextField();
textfield.setToolTipText("<your help string here>");

You can use the JtextField#setToolTipText(tipText) method for that(note that JTextField extends JTextComponent which extends JComponent ).

String toolTip = "Welcome";
myTextField.setToolTipText(toolTip);

Have a look at the javadocs for detailed explanation on using ToolTips .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM