17.文本域、JScroll面板

JPanel面板:重点,布局有间距
 1 package com.gui.lesson4;
 2 
 3 import javax.swing.*;
 4 import java.awt.*;
 5 
 6 public class JPanelDemo extends JFrame {
 7     public JPanelDemo() {
 8         Container container = this.getContentPane();
 9 
10         container.setLayout(new GridLayout(2, 1, 10, 10));//后面两个参数的意思,间距
11 
12         JPanel jPanel = new JPanel(new GridLayout(1, 3));
13         JPanel jPane2 = new JPanel(new GridLayout(1, 2));
14         JPanel jPane3 = new JPanel(new GridLayout(2, 1));
15         JPanel jPane4 = new JPanel(new GridLayout(3, 2));
16 
17         jPanel.add(new JButton("1"));
18         jPanel.add(new JButton("1"));
19         jPanel.add(new JButton("1"));
20         jPane2.add(new JButton("2"));
21         jPane2.add(new JButton("2"));
22         jPane3.add(new JButton("3"));
23         jPane3.add(new JButton("3"));
24         jPane4.add(new JButton("4"));
25         jPane4.add(new JButton("4"));
26         jPane4.add(new JButton("4"));
27         jPane4.add(new JButton("4"));
28         jPane4.add(new JButton("4"));
29         jPane4.add(new JButton("4"));
30 
31         container.add(jPanel);
32         container.add(jPane2);
33         container.add(jPane3);
34         container.add(jPane4);
35 
36         setVisible(true);
37         setSize(500, 500);
38         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
39 
40     }
41 
42     public static void main(String[] args) {
43         new JPanelDemo();
44     }
45 }
View Code

文本域,JScrollPanel面板:滚动
 1 package com.gui.lesson4;
 2 
 3 import javax.swing.*;
 4 import java.awt.*;
 5 
 6 public class JScrollDemo extends JFrame {
 7     public JScrollDemo() {
 8         Container container = this.getContentPane();
 9 
10         //文本域
11         JTextArea textArea = new JTextArea(20, 50);
12         textArea.setText("欢迎学习Java");
13 
14         //Scroll面板
15         JScrollPane scrollPane = new JScrollPane(textArea);
16         container.add(scrollPane);
17 
18         this.setVisible(true);
19         this.setBounds(100, 100, 300, 150);
20         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
21     }
22 
23     public static void main(String[] args) {
24         new JScrollDemo();
25     }
26 }
View Code

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值