面板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. 十几分钟让你学会MySQL布尔和延迟盲注手工操作

    作者:Max老白Gān丶链接:http://www.lofter.com/lpost/1fefbc76_12d25dc31来源:LOFTER 注入常用到的几个函数   1 mid(str,1,3) 字 ...

  2. Python必学Django框架,入门到精通学习视频教程全都在这可以领

    “人生苦短,我用python”,学python的小伙伴应该都了解这句话的含义.但是,学python,你真正了了解强大的Django框架吗!? 据说Django还是由吉普赛的一个吉他手的名字命名的呢,有 ...

  3. [Swift]LeetCode377. 组合总和 Ⅳ | Combination Sum IV

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  4. [Swift]LeetCode522. 最长特殊序列 II | Longest Uncommon Subsequence II

    Given a list of strings, you need to find the longest uncommon subsequence among them. The longest u ...

  5. Spring中的IOC_源码_随笔

    Spring ioc 叫控制反转,也就是把创建Bean的动作交给Spring去完成. spring ioc  流程大致为 定位-> 加载->注册 先说几个比较有意思的点 1.Spring中 ...

  6. Windows提权与开启远程连接

    1.提权: 建立普通用户:net user 帐户 密码 /add 提权成管理员:net localgroup administrators 帐户 /add 更改用户密码:net user 帐户 密码 ...

  7. C++ 断言

    assert宏 (基本概念与用法整理) assert宏的深入学习 1.运行时断言 1.1.assert属于运行时断言,可以在运行时判断给定条件是否为真,如果为真则什么也不做,否则打印一跳错误信息,然后 ...

  8. Steeltoe之Distributed Tracing篇

    Steeltoe里的分布式追踪功能与Spring Cloud Sleuth一样,支持在日志中记录追踪数据,或者上传到远端的服务,比如Zipkin. Logging 在Steeltoe中使用日志时需要引 ...

  9. C#版(打败97.89%的提交) - Leetcode 202. 快乐数 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...

  10. HashMap扩容全过程

      1.如果HashMap的大小超过了负载因子(load factor)定义的容量,怎么办? 默认的负载因子大小为0.75,也就是说,当一个map填满了75%的bucket时候,和其它集合类(如Arr ...