Question about java transperancy

I'm trying to make it so that my JPanel is transparent and shows the frame behind it (it's background is green). But when i start the program the JPanel is there and i see no green. Here is my code

public static void main (String [] args)

{

frame = new JFrame("FrameDemo");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel = new JPanel(new GridBagLayout());

panel.setOpaque(false);

frame.getContentPane().add(panel, BorderLayout.CENTER);

frame.pack();

frame.setVisible(true);

frame.setBackground(Color.green);

}

[604 byte] By [P.F.a] at [2007-11-27 8:35:46]
# 1
Funny - I get the same result.But this workaround was OK on my machine:panel.setOpaque(true);panel.setBackground(new Color(0,0,0,1));
rebola at 2007-7-12 20:32:27 > top of Java-index,Desktop,Core GUI APIs...
# 2
This depends on JPanel's UI delegate honoring opaqueness, i.e. it's a look and feel issue.
dwga at 2007-7-12 20:32:27 > top of Java-index,Desktop,Core GUI APIs...
# 3

Setting the background of the frame does nothing because the frame contains a content pane (which is actually a JPanel). So when you add your panel to the content pane you are doing just that, adding it to the content pane, not the frame directly.

You need to set the background of the content pane:

frame.getContentPane().setBackground(....);

camickra at 2007-7-12 20:32:27 > top of Java-index,Desktop,Core GUI APIs...