English 中文(简体)
Java - 翻译材料
原标题:Java - Transparent JScrollPane

我有一个JTextArea,在JCrollPane上任。 任何途径,我都知道,我可以使用<条码>第(c)/条码>方法确定观察所的不透明财产,但我似乎无法找到任何迹象显示如何在任何地方这样做。

这就是我迄今为止所做的事情:

if (e.getKeyCode() == KeyEvent.VK_F)
{
    if (sp.isVisible())
    {
        sp.setVisible(false);
    }
    else
    {
        sp.setVisible(true);
    }
}
最佳回答

你与@Serplat的勾结表明,你可能会混淆opacitytransparency

<>,是用于优化提取的Sing 部件的生物财产:

  • true: The component agrees to paint all of the bits contained within its rectangular bounds.
  • false: The component makes no guarantees about painting all the bits within its rectangular bounds.

<https://sites.google.com/site/drjohnbmatthews/composite”rel=“nofollow noretinger”>Transparency,是构成数字图像的手段,见example

考虑到这一区别可能有助于澄清你的问题,或有助于你寻求更多信息。

增编:根据example ,以下实例显示,在电离层上,“标准”为蓝广场,而电离板可以滚动。

“ScrollPanePaint”/

import java.awt.*;
import javax.swing.*;

/** @see https://stackoverflow.com/questions/2846497 */
public class ScrollPanePaint extends JFrame {

    private static final int TILE = 64;

    public ScrollPanePaint() {
        JViewport viewport = new MyViewport();
        viewport.setView(new MyPanel());
        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setViewport(viewport);
        this.add(scrollPane);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.pack();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    private static class MyViewport extends JViewport {

        public MyViewport() {
            this.setOpaque(false);
            this.setPreferredSize(new Dimension(6 * TILE, 6 * TILE));
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(Color.blue);
            g.fillRect(TILE, TILE, 3 * TILE, 3 * TILE);
        }
    }

    private static class MyPanel extends JPanel {

        public MyPanel() {
            this.setOpaque(false);
            this.setPreferredSize(new Dimension(9 * TILE, 9 * TILE));
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(Color.lightGray);
            int w = this.getWidth() / TILE + 1;
            int h = this.getHeight() / TILE + 1;
            for (int row = 0; row < h; row++) {
                for (int col = 0; col < w; col++) {
                    if ((row + col) % 2 == 0) {
                        g.fillRect(col * TILE, row * TILE, TILE, TILE);
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new ScrollPanePaint();
            }
        });
    }
}
问题回答

您需要使用<代码>setOpaque(false),使之透明。 呼吁在联合材料数据库中和在《观点》上都使用。

sp.setOpaque(false);
sp.getViewport().setOpaque(false);

如果你也希望这一透明的话,你还必须在JTextArea上打setOpaque(false)

Code for JScrollpane Transdou context.

  JScrollPane scrollPane = new JScrollPane();

   JViewport viewport = new JViewport();


 //Component that need to be added in Scroll pane//

   viewport.setView(new JPanel());

   viewport.setOpaque(false);

   scrollPane.setViewport(viewport);

   scrollPane.getViewport().setOpaque(false);

   scrollPane.setOpaque(false);

 // Add Scrollpane to Jframe or JPanel//

   add( scrollPane,BorderLayout.CENTER); 




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签