[英]How do I put html in a JLabel in java?
How do I use html tags in a JLabel in java?如何在 java 的 JLabel 中使用 html 标签?
To put html in a JLabel
, you would make it look something like this要将 html 放在
JLabel
中,您可以让它看起来像这样
JLabel label = new JLabel("<html><yourTagHere><yourOtherTagHere>this is your text</yourOtherTagHere></yourTagHere></html>");
This will do the trick:这可以解决问题:
String labelText ="<html><FONT COLOR=RED>Red</FONT> and <FONT COLOR=BLUE>Blue</FONT> Text</html>";
JLabel coloredLabel =new JLabel(labelText);
There are following ways有以下几种方式
Using SetText method of JLabel Object使用 JLabel Object 的 SetText 方法
JLabel HTMLlabel = new JLabel().setText("<html><tag>blah blah</tag></html>");
Passing String to JLable class Constructor.将字符串传递给 JLable class 构造函数。
JLabel HTMLlabel = new JLabel("<html><tag>blah blah</tag></html>");
Using String and passing it to JLabel class Constructor similar to above example but using String.使用字符串并将其传递给 JLabel class 构造函数,类似于上面的示例,但使用字符串。
String HTMLlabelStr = "<html><tag>blah blah</tag></html>";
JLabel HTMLlabel = new JLabel(HTMLlabelStr);
This should do the trick:这应该可以解决问题:
JLabel whatever =
new JLabel("<html><something>Put Stuff Here</something></html>");
JLabel myHTMLLabel =new JLabel("<html>");
myHTMLLabel.setText("<html><font color='green'>Hello World</font>");
Also you can use this with all Swing buttons, menu items, labels, text panes, editor panes, tool tips, tabbed panes etc...您也可以将它与所有 Swing 按钮、菜单项、标签、文本窗格、编辑器窗格、工具提示、选项卡式窗格等一起使用...
JTextPane pane = new JTextPane();
pane.setContentType("text/html");
pane.setText("<html><h1>My First Heading</h1><p>My first paragraph.</p></body></html>");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.