Name: rlT66838 Date: 08/09/99
I'd like to make my JTabbedPane transparent, so the background shows up in the area around the tabs (e.g. the area to the right of the tabs, when the tabs are in the upper-left corner). But when I do this, the tabbed pane's content area becomes transparent too. This is not the right thing - it breaks the abstraction that this is an actual panel that other things can be placed on. It now looks like it's got a hole in the middle. What's more, if I try to get rid of the hole by placing an opaque JPanel on each tab pane, there's a ring of transparency around each of my JPanels. This seems to be a no-man's land which is not painted either by the JTabbedPane or its contents.
import javax.swing.*;
import java.awt.*;
public class TabTest2
{
public final static void main (String[] args)
{
// Create frame
JFrame f = new JFrame("hi");
f.setBounds(100,100,400,400);
JPanel p = new JPanel();
p.setBackground(Color.red);
p.setLayout(null);
f.getContentPane().add(p);
// Create tab pane
JTabbedPane t = new JTabbedPane();
t.setBounds(50, 50, 300, 200);
JLabel x = new JLabel("transparent");
x.setOpaque(false);
t.addTab("transparent", x);
JLabel y = new JLabel("opaque");
y.setOpaque(true);
t.addTab("opaque", y);
p.add(t);
// Show the frame.
f.show();
}
}
(Review ID: 93708)
======================================================================