面板JPanel】 面板就是一个容器 每一个容器都可以有一个自己的独立的布局和组件,这些容器之间也不会互相干扰

//导入Java类
import javax.swing.*;
import java.awt.*;
public class Demo extends JFrame{
public Demo(){
setBounds(100,100,500,300);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container c=getContentPane();
c.setLayout(new GridLayout(2,2)); //创建新的组件 JPanel面板
JPanel p1=new JPanel(new GridLayout(1,3,10,10));//布局可写在组件内
//p1.setLayout(new GridLayout(1,3,10,10));
JPanel p2=new JPanel(new BorderLayout());
JPanel p3=new JPanel(new GridLayout(1,2,10,10));
JPanel p4=new JPanel(new GridLayout(2,1,10,10)); //给每个面板设置边框
p1.setBorder(BorderFactory.createTitledBorder("面板1"));//设置面板
p2.setBorder(BorderFactory.createTitledBorder("面板2"));
p3.setBorder(BorderFactory.createTitledBorder("面板3"));
p4.setBorder(BorderFactory.createTitledBorder("面板4")); //给每个面板添加JButton组件
//设置四个按钮的原因:我们网格布局是1,3 网格布局的优势:多添加或少添加组件行不变,列变
p1.add(new JButton("p1"));
p1.add(new JButton("p1"));
p1.add(new JButton("p1"));
p1.add(new JButton("p1")); p2.add(new JButton("p2"),BorderLayout.CENTER);
p2.add(new JButton("p2"),BorderLayout.EAST);
p2.add(new JButton("p2"),BorderLayout.WEST);
p2.add(new JButton("p2"),BorderLayout.SOUTH);
p2.add(new JButton("p2"),BorderLayout.NORTH); p3.add(new JButton("p3")); p3.add(new JButton("p3")); p4.add(new JButton("p4")); p4.add(new JButton("p4"));
//可设置美观的 例如背景颜色
p4.setBackground(Color.BLUE);
c.add(p1);c.add(p2);c.add(p3);c.add(p4);
setVisible(true);
} public static void main(String[] args) {
new Demo();
}
}

滚动面板 JScrollPane

//导入Java类
import javax.swing.*;
import java.awt.*;
public class Demo extends JFrame{
public Demo(){
setBounds(100,100,100,150);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container c=getContentPane();
JTextArea t=new JTextArea();//创建文本域
JScrollPane s=new JScrollPane(t);//创建滚动面板 将t(文本域添加到组建中)
c.add(s);//将滚动面板添加到容器中 setVisible(true);
}
public static void main(String[] args) {
new Demo();
   }
}

面板JPanel,滚动面板JScrollPane,文本域JTextArea的更多相关文章

  1. 面板 JPanel,滚动面板 JScrollPane,文本域JTextArea

    容器中可以有多个JPanel面板,一个JPanel面板中可以有多个控件. 滚动面板 JScrollPane中只能有一个控件.       public class Demo extends JFram ...

  2. JScrollPane (滚动面板)使用心得

    注意:使用滚动面板时,必须指定内部组件是哪个组件 JScrollPane的两种使用方式:. 方式一: //直接在创建滚动面板对象时,就指定所要显示的组件 //本例中所要显示的是jPanel JPane ...

  3. JAVA 如何使JScrollPane中的JTextArea自动滚动到最后一行?

    1.要使JTextArea带有滚动条,需将JTextArea对象添加到JScrollPane中. JTextArea logArea = new JTextArea(15, 35); //创建JTex ...

  4. java在线聊天项目0.4版本 制作服务端接收连接,客户端连接功能 新增客户端窗口打开时光标指向下边文本域功能,使用WindowListener监听WindowAdapter

    建一个服务端类ChatServer,用于设置端口接收连接 package com.swift; import java.io.IOException; import java.net.ServerSo ...

  5. javaSwing文本域文件

    public class JTextAreaTest extends JFrame{    public JTextAreaTest()    {            setSize(200, 40 ...

  6. JAVA个人小程序GUI篇-收银(标签、按钮、复选框、下拉标、文本域、表格······)

    如果用eclipse需先装载windowsbuild //导入包 import java.awt.BorderLayout; import java.awt.EventQueue; import ja ...

  7. 【Swing/文本组件】定义自动换行的文本域

    文本域组件:Swing中任何一个文本域(JTextArea)都是JTestArea类型的对象.常用的构造方法如下 public JTextArea() public JTextArea(String ...

  8. Swing文本域的编辑

    1..setEditable(false); 设置文本域不可编辑 2..setHorizontalAlignment(JTextField.CENTER); // 设置文本的水平对齐方式 有效值包括: ...

  9. textarea文本域的高度随内容的变化而变化

    用css控制textarea文本域的高度随内容的变化而变化,不出现滚动条. CSS代码: 复制代码 代码如下: .t_area{ width:300px; overflow-y:visible } & ...

随机推荐

  1. [Swift]LeetCode56. 合并区间 | Merge Intervals

    Given a collection of intervals, merge all overlapping intervals. Example 1: Input: [[1,3],[2,6],[8, ...

  2. [Swift]LeetCode725. 分隔链表 | Split Linked List in Parts

    Given a (singly) linked list with head node root, write a function to split the linked list into k c ...

  3. [Swift]LeetCode781. 森林中的兔子 | Rabbits in Forest

    In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how ...

  4. [Swift]LeetCode863. 二叉树中所有距离为 K 的结点 | All Nodes Distance K in Binary Tree

    We are given a binary tree (with root node root), a targetnode, and an integer value K. Return a lis ...

  5. 性能调优之Transformation

    优化之Aggregator组件 优化之Custom组件 优化之Joiner组件 优化之Lookup组件 优化之Normalizer组件 优化之Sequence Generator组件 优化之Sorte ...

  6. Python内置函数(49)——pow

    英文文档: pow(x, y[, z]) Return x to the power y; if z is present, return x to the power y, modulo z (co ...

  7. 通过Python、BeautifulSoup爬取Gitee热门开源项目

    一.安装 1.通过requests 对响应内容进行处理,requests.get()方法会返回一个Response对象 pip install requests 2.beautifulSoup对网页解 ...

  8. Chapter 5 Blood Type——4

    "Does he mean you?" Jessica asked with insulting astonishment in her voice. “他对你有意思吗?”Jess ...

  9. RabbitMQ消息队列(五)-安装amqp扩展并订阅/发布Demo(.Net Core版)

    publish发布消息 新建一个Asp.Net Core控制台项目:PublishDemo 安装Nuget包 Install-Package RabbitMQ.Client 添加命名空间引用 usin ...

  10. spring学习(五) ———— 整合web项目(SSM)

    一.SSM框架整合 1.1.整合思路 从底层整合起,也就是先整合mybatis与spring,然后在编写springmvc. 1.2.开发需求 查询商品列表(从数据库中查询) 1.3.创建web工程 ...