Hi there,
I am using my own custom component for a JTabbedPanes tab component. My custom component consists of a JLabel and a JButton (to close the tab).
Code of the custom component:
This is how I setup my tabbed pane:protected static class Tab extends JPanel { private static final long serialVersionUID = 1L; private static Icon cachedIcon = null; private final JButton btnClose; public Tab(Ref ref) { super(); if (cachedIcon == null) { String iconPath = "/javax/swing/plaf/metal/icons/ocean/close.gif"; cachedIcon = new ImageIcon(Tab.class.getResource(iconPath)); } setLayout(new GridLayout(0, 2, 0, 0)); JLabel lblName = new JLabel(ref.getName()); add(lblName); btnClose = new JButton(cachedIcon); add(btnClose); } public void addActionListener(ActionListener l) { btnClose.addActionListener(l); } public void removeActionListener(ActionListener l) { btnClose.removeActionListener(l); } }
addTab(ref.getName(), panel); Tab tab = new Tab(ref); setTabComponentAt(indexOfComponent(panel), tab);
When the tabbed pane is drawn it looks like this:
image1.jpg
The tab in the center is selected. You can clearly see, that the area of the JLabel uses a grey background although the rest of the tab component is light blue.
What should I do to make the JLabels backdrop transparent?
Thank you all for the help.