给javax.swing.text.html.HTMLDocument;加一个网址外联Style,给一个例子
时间: 2024-05-03 09:20:19 浏览: 14
好的,您可以参考下面的代码示例:
```java
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet;
public class Test {
public static void main(String[] args) {
HTMLDocument doc = new HTMLDocument();
StyleSheet styleSheet = doc.getStyleSheet();
styleSheet.addRule("body {font-family: Arial,sans-serif; color: #333;}");
styleSheet.addRule("a { text-decoration: none; color: blue; }");
styleSheet.addRule("a:hover { text-decoration: underline; }");
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
doc.putProperty("stream", System.out);
}
}
```
以上示例代码给 HTMLDocument 加了一个外联样式表,其中 "body" 设置了字体和颜色, "a" 设置了去掉下划线和鼠标悬停下划线效果,并设置了超链接颜色为蓝色。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)