I am writing a program GUI in java. I want to hava a JLayeredPane as ContentPane of my JFrame. On my JLayeredPane there are two layers : one layer a Canvas(canvas1) and another layer has a JPanel(jPanel5). I use Netbeans IDE and this code is generated:
canvas1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
canvas1.setBounds(0, 0, -1, -1);
jLayeredPane1.add(canvas1, javax.swing.JLayeredPane.PALETTE_LAYER);
jPanel5.setBounds(0, 0, 670, 550);
jLayeredPane1.add(jPanel5, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 670, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 553, Short.MAX_VALUE)
);
pack();
when I run my program I saw a strange event! When I change size of tje JFrame; the size of main JLayeredPane did not change. I used diffrerent backGround colours for components and it is obvious to me that the size of JLayered is permanent however I set it vertical and horizonal resizable in it's properties. The JFrame is resizable but main jLayeredPane's size is permamnet.
How can I cause the jLayeredPane to resize as my JFrame ?!
thank you
Try using the default BorderLayout instead of the GroupLayout you're using now. Simply comment out the group of lines that start with creating the GroupLayout and add this line:
The BorderLayout.CENTER parameter to the .add() method tells the BorderLayout manager that you want the given widget to fill the center of your window.