使用&害羞;在支持Java的HTML组件中 [英] Using ­ in Java HTML aware Component

查看:137
本文介绍了使用&害羞;在支持Java的HTML组件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:

我使用JTextPane显示HTML文档。



在我的HTML-Text有& shy; 做出软连接。
我的问题是,没有连字符出现。是否有某种标志,我不知道,使用这些选项?



以下程序将显示问题:

  package com.dvelop.ckue.swing; 

import javax.swing。*;
import javax.swing.text.html.HTMLEditorKit;
import java.awt。*;

public class SwingGui extends JFrame {

public static void main(String [] args){
SwingGui sg = new SwingGui();
sg.setSize(new Dimension(200,800));
sg.setPreferredSize(new Dimension(200,800));
sg.pack();
sg.setVisible(true);
sg.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


private SwingGui(){
super();
setLayout(new FlowLayout());

//不显示 - ,但换行符
add(createField(< html> longlong< br> longlong< br> longlonglonglonglonglonglonglongWord));
//没有换行符,但是连字符符号
add(createField(< html> longlong& shy; longlong& shy; longlonglonglonglonglonglonglongWord));
// Linebreak,但不是在预期的位置,并且没有符号
add(createField(< html> longlong& 8203; longlong& 8203; longlonglonglonglonglonglonglongWord));
//没有换行符,没有符号
add(createField(< html> longlonglonglonglongWord));
}

private JTextPane createField(String content){
JTextPane field1 = new JTextPane();
field1.setPreferredSize(new Dimension(100,200));
field1.setAutoscrolls(true);
field1.setEditorKit(new HTMLEditorKit());
field1.setText(content);
返回field1;
}

}

我的预期行为是,我的文本将被分解到下一行:

  longlong- 
longlong-
longlonglonglongWord

看起来像第一个块,但带有连字符。



编辑:
它可以在大多数浏览器中使用,但我不在这里使用web浏览器。



编辑2:
我使用JTextPane,我不知道Java是否会在内部使用一些安装HTML渲染引擎。 >

解决方案

http:/ /java-sl.com/Hyphenation_In_JEditorPane.html
这是一个自定义hyphnation的例子。您可以使用相同的方法并更改HTMLEditorKit以使用连字符。


I have following problem:

I display an HTML-Document with an JTextPane.

In my HTML-Text there are &shy; (shy at w3.org) to make a soft-hyphenation. My problem is, that no hyphenation appears. Is there some kind of flag, which I don't know, to use these option?

Following Programm will show the problem:

package com.dvelop.ckue.swing;

import javax.swing.*;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;

public class SwingGui extends JFrame {

    public static void main(String[] args) {
        SwingGui sg = new SwingGui();
        sg.setSize(new Dimension(200, 800));
        sg.setPreferredSize(new Dimension(200, 800));
        sg.pack();
        sg.setVisible(true);
        sg.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    private SwingGui() {
        super();
        setLayout(new FlowLayout());

        // No "-" appears, but a linebreak
        add(createField("<html>longlong<br>longlong<br>longlonglonglonglonglonglonglonglonglongWord"));
        // No linebreak, but the hyphenationsymbol
        add(createField("<html>longlong&shy;longlong&shy;longlonglonglonglonglonglonglonglonglongWord"));
        // Linebreak, but not where expected and no symbol            
        add(createField("<html>longlong&#8203;longlong&#8203;longlonglonglonglonglonglonglonglonglongWord"));
        // No linebreak, no symbol
        add(createField("<html>longlonglonglonglonglonglonglonglonglonglonglonglonglongWord"));
    }

    private JTextPane createField(String content) {
        JTextPane field1 = new JTextPane();
        field1.setPreferredSize(new Dimension(100, 200));
        field1.setAutoscrolls(true);
        field1.setEditorKit(new HTMLEditorKit());
        field1.setText(content);
        return field1;
    }

}

My expected behavior is, that my text will be broken to the next line:

longlong- 
longlong-
longlonglonglongWord

As seem by the first block, but with an hyphenation-sign.

EDIT: It will work in most browsers, but I don't use a webbrowser here.

EDIT 2: I use a JTextPane, I don't know, if Java will use some installes HTML rendering-engine internally.

解决方案

http://java-sl.com/Hyphenation_In_JEditorPane.html That's an example of custom hyphnation. You can use the same approach and change the HTMLEditorKit to use your hyphens.

这篇关于使用&amp;害羞;在支持Java的HTML组件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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