相关疑难解决方法(0)

从现有创建自定义swing组件

所以,我有这个JTexrtArea几乎完全满足我的需求.唯一不对的是线间距.我无法设置它.(为什么不使用JTextPane?因为在JTextArea中可以更改间距,而JTextArea比JTextPane更轻,我的程序中有很多这样的东西).

我之前已经问过这个问题,这是我从用户StanislavL得到的答案:


要覆盖JTextArea的行间距,请查看PlainView(用于呈现PLainDocument).

public void paint(Graphics g,Shape a)方法中有以下几行

    drawLine(line, g, x, y);
    y += fontHeight;
Run Code Online (Sandbox Code Playgroud)

因此,您可以调整渲染固定y偏移.

在BasicTextAreaUI方法中创建视图.将其替换为您自己的PlainView实现

public View create(Element elem) {
Document doc = elem.getDocument();
Object i18nFlag = doc.getProperty("i18n"/*AbstractDocument.I18NProperty*/);
if ((i18nFlag != null) && i18nFlag.equals(Boolean.TRUE)) {
    // build a view that support bidi
    return createI18N(elem);
} else {
    JTextComponent c = getComponent();
    if (c instanceof JTextArea) {
    JTextArea area = (JTextArea) c;
    View v;
    if (area.getLineWrap()) {
        v = new WrappedPlainView(elem, area.getWrapStyleWord());
    } else {
        v = …
Run Code Online (Sandbox Code Playgroud)

java swing jtextarea

4
推荐指数
2
解决办法
823
查看次数

标签 统计

java ×1

jtextarea ×1

swing ×1