java修改html样式,java-在JEditorPane或JTextPane中设置HTML样式

我想在JEditorPane或JTextPane中显示HTML,但我希望样式(字体大小)来自外观.有没有办法做到这一点,还是必须使用嵌入式HTML样式?

这是一个例子:

epText = new JEditorPane("text/html", content);

StyleSheet ss = ((HTMLEditorKit)epText.getEditorKit()).getStyleSheet();

ss.addRule("p {font-size:" + FontManager.getManager().getFontSize() + "}");

HTMLEditorKit kit = (HTMLEditorKit) epText.getEditorKit();

kit.setStyleSheet(ss);

epText.setEditorKit(kit);

每当我设置编辑器工具包时,所有文本都会消失.我是否需要每次设置文字?

解决方法:

是.

从Java API for HTMLEditorKit深入研究此代码段:

Customization from current LAF

HTML provides a well known set of features without exactly specifying

the display characteristics. Swing has

a theme mechanism for its

look-and-feel implementations. It is

desirable for the look-and-feel to

feed display characteristics into the

HTML views. An user with poor vision

for example would want high contrast

and larger than typical fonts.

The support for this is provided by the StyleSheet class. The

presentation of the HTML can be

heavily influenced by the setting of

the StyleSheet property on the EditorKit.

编辑:设置编辑器工具包时,它会卸载旧工具包并安装新工具包.这改变了基础模型,这就是为什么文本“消失”的原因.

Read the API for more info.

但是您可能不需要重新创建整个套件…只需在样式中添加一个新表即可.

标签:jeditorpane,swing,html,java

来源: https://codeday.me/bug/20191210/2099810.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值