zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    搭建kafka集群
    fluentd 安装、配置、使用介绍
    彻底解决 es 的 unassigned shards 症状
    nginx 反向代理时丢失端口的解决方案
    kubernetes的imagePullSecrets如何生成及使用
    创建MySQL数据库账号
    Linux中查找文件
    Linux快速访问多个目录
    Django查询数据库返回字典dict数据
    linux 将压缩包复制到另外一个文件夹下面
  • 原文地址:https://www.cnblogs.com/duanfu/p/12599607.html
Copyright © 2011-2022 走看看