I would like to have a GUI setup as shown below.

JLayeredPane must always be the same size, but JPanel and JScrollPane can vary in size. I need a JScrollPane to display the JLayedPane by clicking the arrows, and what not if the JPanel and JScrollPane not large enough to show the entire JLayeredPane .
The problem is that with the code below, the JLayeredPane always expands to fit the size of the JScrollPane , and if the JScrollPane smaller than the JLayeredPane , it does not provide scrolling ability.
Any ideas on what's going on? Is there a simpler code for this?
thanks
contentPanePanel = new javax.swing.JPanel(); contentPaneScollPane = new javax.swing.JScrollPane(); contentPane = new javax.swing.JLayeredPane(); contentPanePanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true)); contentPane.setRequestFocusEnabled(false); contentPane.setVerifyInputWhenFocusTarget(false); contentPaneScollPane.setViewportView(contentPane); javax.swing.GroupLayout contentPanePanelLayout = new javax.swing.GroupLayout(contentPanePanel); contentPanePanel.setLayout(contentPanePanelLayout); contentPanePanelLayout.setHorizontalGroup( contentPanePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(contentPaneScollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 968, Short.MAX_VALUE) ); contentPanePanelLayout.setVerticalGroup( contentPanePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(contentPaneScollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 628, Short.MAX_VALUE) );
source share