怎样设置字体颜色?java swing
"<html>"+rs.getString(2)+"<br>"+rs.getString(3)+"<br>"+rs.getString(4)+"</html>"我只想设置...
"<html>"+rs.getString(2)+"<br>"+rs.getString(3)+"<br>"+rs.getString(4)+"</html>"我只想设置rs.getString(2)的字体颜色,rs.getString(2),rs.getString(3)是在数据库中调取的数据
展开
2个回答
展开全部
swing支持html及样式表。不过有些标记不支持,我记得span不支持
下边是例子
------------------------------------------------------------------------------------------------------------
import javax.swing.JFrame;
import javax.swing.JLabel;
public class FontApp extends JFrame {
public FontApp() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400, 300);
setLocationRelativeTo(null);
setResizable(false);
getContentPane().setLayout(null);
String str = "<html><font style=\"color:red;\">111111111</font><br>2222222222222<br>333333333</html>";
JLabel lblNewLabel = new JLabel(str);
lblNewLabel.setToolTipText(str);
lblNewLabel.setBounds(37, 55, 199, 66);
getContentPane().add(lblNewLabel);
setVisible(true);
}
public static void main(String[] args) {
new FontApp();
}
}
下边是例子
------------------------------------------------------------------------------------------------------------
import javax.swing.JFrame;
import javax.swing.JLabel;
public class FontApp extends JFrame {
public FontApp() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400, 300);
setLocationRelativeTo(null);
setResizable(false);
getContentPane().setLayout(null);
String str = "<html><font style=\"color:red;\">111111111</font><br>2222222222222<br>333333333</html>";
JLabel lblNewLabel = new JLabel(str);
lblNewLabel.setToolTipText(str);
lblNewLabel.setBounds(37, 55, 199, 66);
getContentPane().add(lblNewLabel);
setVisible(true);
}
public static void main(String[] args) {
new FontApp();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询