2
How could I format with different "properties" a JLabel
and its content?
For example, I wish I could set a color for my text JLabel
, and another to string
that this concatenated with it. It is possible?
In my case, he was alone in a "way", and the html
that I tried to use, also did not work.
What I tried to:
import java.awt.Color;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Teste extends JFrame {
public static void main(String[] args) {
new Teste().setVisible(true);
}
private JPanel painel = new JPanel();
private Font fonte = new Font("SansSerif", Font.BOLD, 15);
private JLabel label = new JLabel();
private String string = "string";
public Teste() {
setSize(500, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
painel.add(label);
add(painel);
label.setText("Label + " + "<html><font color=#166B44> " + string + " </font></html>");
label.setFont(fonte);
label.setForeground(Color.red);
}
}