在Java Swing Elements中使用HTML样式是不好的做法吗? [英] Is it Bad Practice to use HTML Styling in Java Swing Elements?

查看:92
本文介绍了在Java Swing Elements中使用HTML样式是不好的做法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用HTML设置Swing元素的样式被认为是不好的做法?

It is considered bad practice to style Swing elements using HTML?

例如,如果我想让标签更大而红色只是一次,我有两个选项:

As an example, if I want to make a label bigger and red just once, I have two options:

使用API​​调用:

JLabel label = new JLabel("This is a title");  
label.setFont(label.getFont().deriveFont(18));  
label.setForeground(Color.red);

或者使用HTML:

JLabel label = new JLabel("<html><font size='4' color='#ff0000'>This is a title");

此外, HTML方式允许我强调一个单词而不是整个标签和其他此类用途。

In addition, the HTML way allows me to emphasise one word instead of a whole label, and other such uses.

使用HTML有什么缺点?它更贵吗?并且所有JRE都不保证格式化吗?

What are the drawbacks of using HTML? Is it more expensive? And is formatting not guaranteed on all JREs?

推荐答案


  1. 不,它还不错或者在Swing JComponents中使用HTML语法的好习惯

  1. No, it is not bad or good practice to use HTML syntax in the Swing JComponents

今天,Java支持HTML 3.2,并且对某些CSS属性的支持减少了

Today, Java supports HTML 3.2 and there is reduced support for certain CSS attributes

JTextPane和JEditorPane支持使用HTML语法添加和定位JComponents

JTextPane and JEditorPane support adding and positioning JComponents using HTML syntax

这篇关于在Java Swing Elements中使用HTML样式是不好的做法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆