I have a frame.
I applyed AbsoluteLayout in this frame Then I added a panel with a GridLayout.
Clicking with mouse left button and Surround with, I chose JscrollPane .
Yhis is the code without Sourround with JScrollPane
package d06.m03;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JScrollPane;
import java.awt.GridLayout;
import java.awt.SystemColor;
public class ActionExample4 extends JFrame {
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ActionExample4 frame = new ActionExample4();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ActionExample4() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 594, 426);
getContentPane().setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(SystemColor.activeCaption);
panel.setBounds(91, 11, 154, 264);
getContentPane().add(panel);
panel.setLayout(new GridLayout(8, 1, 1, 2));
for(int i=0;i<9;i++)
{
JPanel panel_1 = new JPanel();
panel.add(panel_1);
}
}
}
and with surround :
package d06.m03;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JScrollPane;
import java.awt.GridLayout;
import java.awt.SystemColor;
public class ActionExample4 extends JFrame {
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ActionExample4 frame = new ActionExample4();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ActionExample4() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 594, 426);
getContentPane().setLayout(null);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(91, 11, 154, 264);
getContentPane().add(scrollPane);
JPanel panel = new JPanel();
scrollPane.setViewportView(panel);
panel.setBackground(SystemColor.activeCaption);
panel.setLayout(new GridLayout(8, 1, 1, 2));
for(int i=0;i<9;i++)
{
JPanel panel_1 = new JPanel();
panel.add(panel_1);
}
}
}
this is the output with both codes:
I want it like this:
Thanks in advance.