Transparent JTabbedPane
I have a background image that I need to show through everything. I created a JTabbedPane on top of the background and it was still fine, but as soon as I put a JPanel into the JTabbedPane it is no longer transparent like I need it. I have set both the JTabbedPane and the JPanel inside to not be opaque. All I can see is the light blue of the selected tab though. Is there a way to make it all completely transparent? Here is my code: JPanel main =new JPanel(){
ImageIcon background =new ImageIcon(getClass().getResource("/com/site/Graphics/background.jpg"));
protectedvoid paintComponent(Graphics g){
g.drawImage(background.getImage(),0,0,null);
}
};
JTabbedPane tab =new JTabbedPane();
tab.setOpaque(false);
JPanel panel =new JPanel();
panel.setOpaque(false);
tab.addTab("Panel", panel);
main.add(tab);
pack();
[1350 byte] By [
drawimagea] at [2007-11-27 10:52:22]

# 3
not sure this is what you're trying to do, but worth a look
import java.awt.*;
import javax.swing.*;
class Testing
{
public void buildGUI()
{
JPanel main = new JPanel(new BorderLayout()) {
ImageIcon background = new ImageIcon(getClass().getResource("test.gif"));
protected void paintComponent(Graphics g) {
g.drawImage(background.getImage(),0,0,this.getPreferredSize().width,this.getPreferredSize().height,null);
}
};
JTabbedPane tab = new JTabbedPane();
tab.setUI(new javax.swing.plaf.basic.BasicTabbedPaneUI(){
protected void paintTabBackground(Graphics g,int tabPlacement,int tabIndex,int x,int y,int w,int h,boolean isSelected){}
protected void paintContentBorder(Graphics g,int tabPlacement,int selectedIndex){}
});
JPanel panel = new JPanel(new GridBagLayout());
panel.setOpaque(false);
panel.setPreferredSize(new Dimension(600,600));
panel.add(new JLabel("Hello World"),new GridBagConstraints());
tab.addTab("Panel", panel);
main.add(tab);
JFrame f = new JFrame();
f.getContentPane().add(main);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Testing().buildGUI();
}
});
}
}