Problem with LayeredPane.

When add component on layered pane they are not shown on the screen,

but without layered pane its working fine.

I couldn't figure out where I miss..

Many Thanks and here is my code.

import java.awt.Color;

import java.awt.GridBagConstraints;

import java.awt.GridBagLayout;

import java.awt.Insets;

import javax.swing.BorderFactory;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JLayeredPane;

import javax.swing.JPanel;

import javax.swing.JTextArea;

import javax.swing.JTextField;

import javax.swing.SwingUtilities;

import javax.swing.border.Border;

import javax.swing.border.EtchedBorder;

publicclass BankAccountDialogextends JFrame{

/**

* @param args

*/

private JPanel bankPanel;

private JPanel accountPanel;

private JPanel mainPanel;

private JTextField tBankName;

private JTextField tBankLink;

private JTextArea tBankAddress;

publicvoid buildBankFrame()

{

Border tBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED,Color.GRAY ,Color.GRAY);

bankPanel =new JPanel();

bankPanel.setBorder(BorderFactory.createTitledBorder("Bank Informations"));

bankPanel.setLayout(new GridBagLayout());

bankPanel.setOpaque(false );

GridBagConstraints gc =new GridBagConstraints();

gc.gridx = 0;

gc.gridy = 0;

gc.weightx = 0;

gc.anchor = GridBagConstraints.EAST;

gc.insets =new Insets(5,5,5,5);

bankPanel.add(new JLabel("Bank Name: "),gc);

tBankName =new JTextField(60);

tBankLink =new JTextField(60);

tBankAddress =new JTextArea(3,60);

tBankName.setBorder(tBorder);

tBankLink.setBorder(tBorder);

tBankAddress.setBorder(tBorder);

tBankAddress.setWrapStyleWord(true);

tBankAddress.setLineWrap(true);

tBankAddress.setOpaque(false);

tBankName.setOpaque(false);

tBankLink.setOpaque(false);

gc.gridx = 1;

gc.weightx = 1;

gc.fill = GridBagConstraints.HORIZONTAL;

gc.anchor = GridBagConstraints.EAST ;

bankPanel.add(tBankName,gc);

gc.gridy = 1; gc.gridx = 0;

gc.anchor = GridBagConstraints.WEST ;

gc.weightx = 0;

bankPanel.add(new JLabel("Website : "),gc);

gc.gridx = 1;

gc.weightx = 1;

bankPanel.add(tBankLink,gc);

gc.gridx = 0;

gc.gridy = 2;

gc.weightx = 0;

bankPanel.add(new JLabel("Address : "),gc);

gc.gridx = 1;

gc.weightx = 1;

bankPanel.add(tBankAddress,gc);

}

publicvoid buildAccountFrame()

{

}

publicvoid buildMainPanel()

{

mainPanel =new JPanel();

GridBagConstraints gc =new GridBagConstraints();

gc.gridx = 0;

gc.gridy = 0;

gc.weightx = 100;

gc.fill = GridBagConstraints.HORIZONTAL;

mainPanel.add(bankPanel,gc);

}

public BankAccountDialog(String title)

{

super(title);

super.setSize(800,600);

}

publicvoid buildLayout()

{

this.getContentPane().setLayout(new GridBagLayout());

GridBagConstraints gc =new GridBagConstraints();

buildBankFrame();

//buildAccountFrame();

buildMainPanel();

gc.fill = GridBagConstraints.BOTH;

//this.getContentPane().add(mainPanel,gc);

this.getLayeredPane().add(mainPanel,new Integer(0));

this.getLayeredPane().setLayer(mainPanel,0,0);

}

publicvoid showOnScreen()

{

SwingUtilities.invokeLater(new Runnable()

{

publicvoid run()

{

BankAccountDialog.this.setVisible(true);

}

});

}

publicstaticvoid main(String[] args){

BankAccountDialog d =new BankAccountDialog("Bank Information");

d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

d.buildLayout() ;

d.showOnScreen();

}

}

[6814 byte] By [chaos_begins_herea] at [2007-11-26 17:30:00]
# 1
The JLayeredPane uses absolute positioning. That means that you have to specify location and size for any components you add to the JLayeredPane.
Jasprea at 2007-7-8 23:57:57 > top of Java-index,Desktop,Core GUI APIs...
# 2
great! it's working now... I'm not aware that layered position uses absolute positioning...and one more doubts. How to disabled Maximize button of window?
chaos_begins_herea at 2007-7-8 23:57:57 > top of Java-index,Desktop,Core GUI APIs...
# 3
frame.setResizable(false);
watfora at 2007-7-8 23:57:57 > top of Java-index,Desktop,Core GUI APIs...
# 4

got it.. Thanks...

and I have one more problem...

I need all my components to show the background and this i achieved. My window will have a background picture, so all components need to be transparent.

But when I added jtextArea inside a jscrollpane, it's not transparent even after setting setOpaque method to false for both.

and I also need to specify the background iamge path relatively. How to do this?

chaos_begins_herea at 2007-7-8 23:57:57 > top of Java-index,Desktop,Core GUI APIs...
# 5

chaos, answers to all of your questions can be easily found via a Google search. Why bother waiting for a response here? Try using Google first, then search the forums, then post a new topic. It should save you and us time.

JLayeredPane - all top 5 results are relevant to what you're trying to do: http://www.google.com/search?q=JLayeredPane

JScrollPane transparency: http://forum.java.sun.com/thread.jspa?threadID=668256&messageID=3908943

Reading an image: http://www.google.com/search?q=Java+read+image

Jasprea at 2007-7-8 23:57:57 > top of Java-index,Desktop,Core GUI APIs...