17-JPanel和JScroll
import java.awt.Color;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Hello{
public static void main(String[] args ) {
new MyJPanel();
}
}
class MyJPanel extends JFrame{
public MyJPanel() {
Container container = this.getContentPane();
container.setLayout(new GridLayout(2,1,10,10));
JPanel jPanel1 = new JPanel(new GridLayout(1,3));
JPanel jPanel2 = new JPanel(new GridLayout(1,2));
JPanel jPanel3 = new JPanel(new GridLayout(2,1));
JPanel jPanel4 = new JPanel(new GridLayout(3,2));
jPanel1.add(new JButton("1"));
jPanel1.add(new JButton("2"));
jPanel1.add(new JButton("3"));
jPanel2.add(new JButton("1"));
jPanel2.add(new JButton("2"));
jPanel3.add(new JButton("1"));
jPanel3.add(new JButton("2"));
jPanel4.add(new JButton("2"));
jPanel4.add(new JButton("2"));
jPanel4.add(new JButton("2"));
jPanel4.add(new JButton("2"));
jPanel4.add(new JButton("2"));
jPanel4.add(new JButton("2"));
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setVisible(true);
this.setSize(500, 500);
container.add(jPanel1);
container.add(jPanel2);
container.add(jPanel3);
container.add(jPanel4);
}
}
import javax.swing.*;
public class Hello{
public static void main(String[] args ) {
new MyJPanel();
}
}
class MyJPanel extends JFrame{
public MyJPanel() {
Container container = this.getContentPane();
JTextArea jTextArea=new JTextArea();
jTextArea.setText("nbuyv");
JScrollPane scrollPane= new JScrollPane(jTextArea);
container.add(scrollPane);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setVisible(true);
this.setSize(500, 500);
}
}