--
Message posted via http://www.javakb.com
You can't in a simple way, since the tooltip system triggers exclusively
on mouse events (plus two keys for accessibility).
You would have to subclass ToolTipManager and override
registerComponent() to register listeners for focus events, too. Then
you have to ensure that your components only use an instance or
instances of your ToolTipManager subclass, instead of the
ToolTipManager.sharedInstance() instance. You would have to override
each and every method of your swing components which use that shared
instance.
/Thomas
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
this coud be difficult job since ToolTipManager has package protected
constructor!
I suggest that you try to create and post MouseEvent if your component gains
or loses focus.
--
Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Oh, I should have spent a few more seconds with the API documentation.
Then there isn't much one can do with the ToolTipManager.
I thing we can move the cursor programaticall when a component gains focus
,do u both feel, that will be an easy solution
--
Hi Praveen,
I looked at source of ToolTipManager and found better solution.
Instead of MouseEvent you should dispatch KeyEvent (CTRL + F1).
______________________________________
package com.imagero.gui.swing;
import javax.swing.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;
import java.awt.*;
public class FocusTest {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT, 10,
10));
JTextField [] field = new JTextField[8];
for (int i = 0; i < field.length; i++) {
field[i] = new JTextField("" + i, 20);
final JTextField jTextField = field[i];
jTextField.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
jTextField.dispatchEvent(
new KeyEvent(
jTextField, 401,
System.currentTimeMillis(), Event.CTRL_MASK, KeyEvent.VK_F1, '?', 1));
}
});
jTextField.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
System.out.println(e.getWhen());
System.out.println(e.getID());
System.out.println(e.getKeyChar());
System.out.println(e.getKeyCode());
System.out.println(e.getKeyLocation());
System.out.println(e.getModifiers());
}
});
jTextField.setToolTipText(jTextField.getText());
jTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jTextField.setToolTipText(jTextField.getText());
}
});
ToolTipManager.sharedInstance().registerComponent(jTextField);
frame.getContentPane().add(jTextField);
}
frame.pack();
frame.show();
}
}
______________________________________
thank you very much for your help.
I have used your idea in my application it works 100%.
Thank u one again
praveen