J
Jim Janney
In Eclipse when you display a tool tip you get a different message if
the control or shift keys are pressed. I'm trying to do the same
thing in a Swing program. My first try was to subclass JTextField
and override getToolTipText(MouseEvent), something like this:
public class CustomTextField extends JTextField {
// usual constructors
@Override
public String getToolTipText(MouseEvent event) {
String result;
if (event.isControlDown() && getAlternateText() != null) {
result = getAlternateText();
} else {
result = super.getToolTipText(event);
}
return result;
}
public String getAlternateText() {
return "get your alternate text here";
}
}
This works for text fields but it's hard to extend it to other kinds
of components. If you have a non-editable combo box the class that
receives the method call is some subclass of JButton, for example
com.jgoodies.looks.plastic.PlasticComboBoxButton: exactly which
one you get depends on the look and feel.
I'm wondering if this is the wrong approach and I should be doing
something with a MouseListener instead. Has anyone else done anything
like this?
the control or shift keys are pressed. I'm trying to do the same
thing in a Swing program. My first try was to subclass JTextField
and override getToolTipText(MouseEvent), something like this:
public class CustomTextField extends JTextField {
// usual constructors
@Override
public String getToolTipText(MouseEvent event) {
String result;
if (event.isControlDown() && getAlternateText() != null) {
result = getAlternateText();
} else {
result = super.getToolTipText(event);
}
return result;
}
public String getAlternateText() {
return "get your alternate text here";
}
}
This works for text fields but it's hard to extend it to other kinds
of components. If you have a non-editable combo box the class that
receives the method call is some subclass of JButton, for example
com.jgoodies.looks.plastic.PlasticComboBoxButton: exactly which
one you get depends on the look and feel.
I'm wondering if this is the wrong approach and I should be doing
something with a MouseListener instead. Has anyone else done anything
like this?