1
I’m trying to print a text on a tooltip, and at the end, put an icon, however I’m not getting it, I tried to do with html.
The problem is that the image comes "broken", does not appear.
What would be the right way to do it?
import java.awt.Dimension;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class ToolTip extends JFrame {
private JTextField jTextField = new JTextField();
public ToolTip() {
add(tela());
setSize(300, 300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private JComponent tela() {
JPanel painel = new JPanel();
painel.add(jTextField);
jTextField.setPreferredSize(new Dimension(150, 20));
jTextField.setToolTipText("Nome do campo: " + personalizaToolTip());
return painel;
}
private String personalizaToolTip() {
//JLabel label = new JLabel();
//label.setIcon(new ImageIcon(getClass().getResource("/imagens/testeIcon.png")));
String texto = "<html><body> o campo esta desabilitado.. <img src=\"/imagens/testeIcon.png\"/> </body></html>";
return texto;
}
public static void main(String[] args) {
ToolTip tp = new ToolTip();
}
}
You can put the icon image there in the question?
– Victor Stafusa
@Victorstafusa I edited !
– JavaTech
Okay, that’s not really what I wanted, but it also helps a lot. What I was saying is, put the image that you want to appear, the
"/imagens/testeIcon.png"
.– Victor Stafusa
@Victorstafusa is just a little blue circle, just to test.
– JavaTech
You need to create a custom tooltip, so ai will not add icone.
– user28595
@Articuno can give me an example, if possible ?
– JavaTech