Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

swing - Java - Transparent JScrollPane

I have a JTextArea and it's riding ontop of a JScrollPane. Anyways, I know I can use the getViewPort() method to set the opaque of of the view port... but I cannot seem to find any sign of how to do that... anywhere. :S

Here is what I have so far:

 if (e.getKeyCode() == KeyEvent.VK_F)
{
    if (sp.isVisible())
    {
        sp.setVisible(false);
    }
    else
    {
        sp.setVisible(true);
    }
}
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to use setOpaque(false) to make it transparent. Call that both on the JScrollPane, and on it's ViewPort.

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

You'll also have to call setOpaque(false) on the JTextArea, if you want that transparent as well.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...