JTextPane / JScrollPane显示问题

问题描述 投票:0回答:1

我正在尝试使用JScrollPane包装JTextPane,我需要背景是透明的。

这是我的代码:

public CharPanel(){

    super.setLayout(null);

    JButton LButton = new JButton("<");
    LButton.setBounds(0, 300, 50, 50);
    super.add(LButton);

    JButton RButton = new JButton(">");
    RButton.setBounds(950, 300, 50, 50);
    super.add(RButton);

    JTextPane Bio = new JTextPane();
    Bio.setBackground(new Color(0, 0, 0, 0));


    JScrollPane BioScroll = new JScrollPane(Bio);
    BioScroll.setBackground(new Color(0, 0, 0, 0));
    BioScroll.setBounds(0, 500, 1000, 150);
    super.add(BioScroll);


}

通常看起来像这样:https://gyazo.com/db7e4d2a5668b36ffc617cefb1423fc4

这是我输入一个角色后的样子:https://gyazo.com/1509d952005195d6e14365f0ae2da69a

看到奇怪的视觉错误?

java swing transparency jscrollpane jtextpane
1个回答
1
投票
Bio.setBackground(new Color(0, 0, 0, 0));

不要使用具有alpha值的颜色。这打破了Swing绘画规则,而Swing不知道如何正确地绘制组件并且你得到绘画工件。

为了完全透明,只需使用:

component.setOpaque( false );

如果您需要使用部分透明度,请查看Backgrounds With Transparency以获取更多相关信息和解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.