glottis
asked on
Custom ToolTips
What I want is that no matter what component is used, the tooltip which is shown (if it is shown) then it should be my own custom made.
for example I want the background color to be Color.ABC and the the font to be be Font.XYZ.
The default tooltip Look and feel should be this, no matter what LnF is installed.
for example I want the background color to be Color.ABC and the the font to be be Font.XYZ.
The default tooltip Look and feel should be this, no matter what LnF is installed.
ASKER
umm.... explanation please :)
the thing is,
Say, you want to display a tool tip with the text field value.
Then you have to use, setToolTipText(text.getTex t());
If you want to display the background color of a component then
setToolTipText(component.g etBackgrou nd().toStr ing());
Same way, you can have your own getter method to populate the tooltip value.
Regards,
Muruga
Say, you want to display a tool tip with the text field value.
Then you have to use, setToolTipText(text.getTex
If you want to display the background color of a component then
setToolTipText(component.g
Same way, you can have your own getter method to populate the tooltip value.
Regards,
Muruga
Hi glottis,
Try this :
JToolTip jtt = component.createToolTip();
jtt.setBackground(Color. ...);
jtt.setFont(new Font( ... ));
Try this :
JToolTip jtt = component.createToolTip();
jtt.setBackground(Color. ...);
jtt.setFont(new Font( ... ));
ASKER
mmuruganandam: youve got me wrong, i donot want to display dynamic content. What I want is that by default all the tooltips which popup should have its properties lets say:
Font = "Times New Roman", Font.PLAIN, 12
Background Color = Color.BLACK
Foreground Color = Color.WHITE
Webstorm:
Currently wha i have done is that I have extended every component and overiden the createToolTip method, but that is a tedious job.
same way your solution would make me re write my entire code so that i may change the tooltip of every component (I have a lot of components).
Font = "Times New Roman", Font.PLAIN, 12
Background Color = Color.BLACK
Foreground Color = Color.WHITE
Webstorm:
Currently wha i have done is that I have extended every component and overiden the createToolTip method, but that is a tedious job.
same way your solution would make me re write my entire code so that i may change the tooltip of every component (I have a lot of components).
Just do this:
JToolTip getToolTip(JComponent jcomp)
{
JToolTip jtt = jcomp.createToolTip();
jtt.setBackground(Color. ...);
jtt.setFont(new Font( ... ));
return jtt;
}
And call it for each component.
Or (better solution) you can create a new look & feel and extend the BasicToolTipUI class.
JToolTip getToolTip(JComponent jcomp)
{
JToolTip jtt = jcomp.createToolTip();
jtt.setBackground(Color. ...);
jtt.setFont(new Font( ... ));
return jtt;
}
And call it for each component.
Or (better solution) you can create a new look & feel and extend the BasicToolTipUI class.
ASKER
Webstorm:
that is what I did, and for some reason (i dont know what) JComboBox was not behaving correctly :)
other components were showing the proper tool tip, but not JComboBox.
One last solution would be to user new LnF.... but still is there any other way ?
that is what I did, and for some reason (i dont know what) JComboBox was not behaving correctly :)
other components were showing the proper tool tip, but not JComboBox.
One last solution would be to user new LnF.... but still is there any other way ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
johnknapp:
thanks for hte help.
i will look into this.
My combox box is editable, and what I did was:
public class MyCombo extends JComboBox {
...
public JToolTip createToolTip() {
...
}
}
however this method was never called. I think I should better set the tooltip on the editor, and the renderer.
Thanks again.
thanks for hte help.
i will look into this.
My combox box is editable, and what I did was:
public class MyCombo extends JComboBox {
...
public JToolTip createToolTip() {
...
}
}
however this method was never called. I think I should better set the tooltip on the editor, and the renderer.
Thanks again.
In the setToolTipText method call that getter methods.
That is the only way to generate the dynamic tooltip irrespective of LnF.
Regards,
Muruga