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();
}
}

