【问题标题】:Can add effects to the text in JTextArea, like alpha, shadow by using graphics2d or grahics?可以使用 graphics2d 或 grahics 为 JTextArea 中的文本添加效果,如 alpha、阴影吗?
【发布时间】:2013-08-27 23:06:56
【问题描述】:

我有一个 JTextArea,里面有文本。我想知道是否可以使用 Graphics2D 为 JTextArea 本身的文本添加效果,例如 alpha 或阴影。

【问题讨论】:

    标签: java swing graphics paint jtextarea


    【解决方案1】:

    这里好像没有人!这不是核武器,伙计们。在互联网上,每个人都受益于其他人,有些问题你找不到,你应该自己解决。就像我在这里做的一样!我完美解决了自己的问题,

    Graphics g = textArea.getGraphics();
    int x = image.getWidth() - fm.stringWidth(string) - 4;
        int y = fm.getHeight();
    g.drawString(textArea.getText(), x, y);
     float alpha = 1.0f;
        int alpha2 = slider1.getValue();
        alpha = (float) alpha2 / 100;
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
    

    就是这样!有一些我不会在这里添加的小东西,以避免给不值得的人带来好处..

    【讨论】:

      【解决方案2】:

      如果您改用 JTextPane,则可以使用 StyledDocument,甚至更简单的 HTML。可以单独设置样式,也可以内联样式。也许不是用 Graphics(2D) 自己做的过多的效果,但很容易。

      【讨论】:

        猜你喜欢
        • 2017-05-11
        • 1970-01-01
        • 2015-01-09
        • 1970-01-01
        • 1970-01-01
        • 2011-03-18
        • 1970-01-01
        • 1970-01-01
        • 2013-12-31
        相关资源
        最近更新 更多