I've seen several similar questions, but unfortunately the suggestions contained therein haven't quite done it for me.
The overall goal: I have a slider that I want to display in the upper left of a window that mainly displays a visualization (here "display"). The slider should overlay on top of the visualization without any background.
So far, I have a JPanel containing my slider on a layer above the visualization in a JLayeredPane. The problem is that, despite calls to setOpaque and/or setBackground(new Color(0,0,0,0)), the background for the JPanel including the slider appears grey. I am using the Nimbus LAF.
Originally, I used an Absolute Layout, which accomplished almost everything quite elegantly and with minimal code. The issue there was that the visualization didn't resize with the window automatically (but I'm open to this approach if there's a clean way to make the visualization resize with the window).
JPanel sliderPane = new JPanel();
sliderPane.setLayout(new BoxLayout(sliderPane, BoxLayout.X_AXIS));
sliderPane.add(zoomSlider);
zoomSlider.setMaximumSize(new Dimension (60, 150));
sliderPane.add(Box.createHorizontalGlue());
sliderPane.setBackground(new Color(0,0,0,0));
JLayeredPane graphPane = new JLayeredPane();
graphPane.setPreferredSize(new Dimension(1000, 800));
graphPane.setLayout(new BoxLayout(graphPane, BoxLayout.Y_AXIS));
graphPane.add(sliderPane, new Integer(1));
graphPane.add(display, new Integer(0));
graphPane.setOpaque(false);
Thanks so much!
Rendering the slider is the responsibility of the component's UI delegate, typically a subclass of BasicSliderUI
. If required, you can substitute your own implementation, as shown here.