JEdi​​torPane半透明背景选择错误 [英] JEditorPane translucent background selection bug

查看:112
本文介绍了JEdi​​torPane半透明背景选择错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JScrollPane内有一个JEditorPane(都是透明的).它们位于具有半透明背景的JPanel内部.当我在JEditorPane中选择文本时,我得到了这个奇怪的错误:

I have a JEditorPane, inside a JScrollPane (both transparrent). These are inside a JPanel which have a translucent background. When i select the text inside the JEditorPane i get this strange bug:

因此,在同一JPanel中没有出现的其他元素,即围绕该选择的鬼影",在此屏幕快照中更加明显:

So the other elements which arent in the same JPanel, "ghost" around the selection, more seen in this screenshot:

Java GUI对我来说是第一个,我只做没有gui的服务器端应用程序.

Java GUI is a first for me, i've only done server-side applications with no gui's.

面板代码:

    @SuppressWarnings("serial")
    public class NewsPanel extends JPanel {

    private JEditorPane newsArea;


    public NewsPanel() {
        setLayout(new BorderLayout());
        setBackground(new Color(226, 0, 0, 179));
        loadContent();
        setSize(500,400);
    }

    private void loadContent() {
        newsArea = new JEditorPane();
        newsArea.setEditable(false);
        newsArea.setBorder(BorderFactory.createEmptyBorder());
        newsArea.setSelectionColor(Color.GRAY);
        newsArea.setOpaque(false);
        newsArea.setBackground(new Color(0, 0, 0, 0));

        HTMLEditorKit kit = new HTMLEditorKit();
         StyleSheet styleSheet = kit.getStyleSheet();
         styleSheet.addRule("A {color:#0088CC}");
         styleSheet.addRule("#newsHeader {font-weight:bold;font-size:14px;color:#339933;}");
         styleSheet.addRule("#newsBody {font-size:10px;padding-left:20px;}");
         newsArea.setEditorKit(kit);


        JScrollPane scrollPane = new JScrollPane(newsArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        add(scrollPane, BorderLayout.CENTER);

        scrollPane.getViewport().setBackground(new Color(0, 0, 0, 0));
        scrollPane.getViewport().setOpaque(false);
        scrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
        scrollPane.setOpaque(false);
        scrollPane.setBackground(new Color(0, 0, 0, 0));
        scrollPane.setBorder(BorderFactory.createEmptyBorder());
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
    }

    @Override
    public boolean isOptimizedDrawingEnabled() {
        return false;
    }

    public void reload() {
        removeAll();
        loadContent();
        validate();
        repaint();
    }
}

任何想法如何解决?我敢肯定它很简单,但是就像我说的那样,我是UI的新手.

Any ideas how to fix? I'm sure its something simple, but like i say, i'm new to UI's

推荐答案

这些位于具有半透明背景的JPanel中.当我在JEditorPane中选择文本时,我得到了这个奇怪的错误:

These are inside a JPanel which have a translucent background. When i select the text inside the JEditorPane i get this strange bug:

查看具有透明度的背景可能的问题和一些解决方案.

Check out Backgrounds With Transparency for the probably problem and a couple of solutions.

这篇关于JEdi​​torPane半透明背景选择错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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