面板 JPanel,滚动面板 JScrollPane,文本域JTextArea
容器中可以有多个JPanel面板,一个JPanel面板中可以有多个控件。
滚动面板 JScrollPane中只能有一个控件。
public class Demo extends JFrame {
public Demo() {
setBounds(100, 100, 600, 200);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new GridLayout(1, 2, 10, 10));
//创建2个面板
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(1, 3));
JPanel p2 = new JPanel(new BorderLayout());
p2.setBackground(Color.BLUE);
//设置面板边框,标题
p1.setBorder(BorderFactory.createTitledBorder("面板1"));
p2.setBorder(BorderFactory.createTitledBorder("面板2"));
p1.add(new JButton("b1"));
p1.add(new JButton("b1"));
p1.add(new JButton("b1"));
p1.add(new JButton("b1"));
p2.add(new JButton("b2"), BorderLayout.EAST);
p2.add(new JButton("b2"), BorderLayout.WEST);
p2.add(new JButton("b2"), BorderLayout.SOUTH);
p2.add(new JButton("b2"), BorderLayout.NORTH);
p2.add(new JButton("b2"));
c.add(p1);
c.add(p2);
setVisible(true);
} public static void main(String[] args) {
new Demo();
}
}
public class Demo extends JFrame {
public Demo() {
setBounds(100, 100, 200, 100);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container c = getContentPane();
JTextArea area=new JTextArea();//文本域
JScrollPane sp=new JScrollPane(area);//将文本域添加到滚动面板中
c.add(sp);
setVisible(true);
} public static void main(String[] args) {
new Demo();
}
}
面板 JPanel,滚动面板 JScrollPane,文本域JTextArea的更多相关文章
- 面板JPanel,滚动面板JScrollPane,文本域JTextArea
[面板JPanel] 面板就是一个容器 每一个容器都可以有一个自己的独立的布局和组件,这些容器之间也不会互相干扰 //导入Java类 import javax.swing.*; import java ...
- JScrollPane (滚动面板)使用心得
注意:使用滚动面板时,必须指定内部组件是哪个组件 JScrollPane的两种使用方式:. 方式一: //直接在创建滚动面板对象时,就指定所要显示的组件 //本例中所要显示的是jPanel JPane ...
- JAVA 如何使JScrollPane中的JTextArea自动滚动到最后一行?
1.要使JTextArea带有滚动条,需将JTextArea对象添加到JScrollPane中. JTextArea logArea = new JTextArea(15, 35); //创建JTex ...
- java在线聊天项目0.4版本 制作服务端接收连接,客户端连接功能 新增客户端窗口打开时光标指向下边文本域功能,使用WindowListener监听WindowAdapter
建一个服务端类ChatServer,用于设置端口接收连接 package com.swift; import java.io.IOException; import java.net.ServerSo ...
- javaSwing文本域文件
public class JTextAreaTest extends JFrame{ public JTextAreaTest() { setSize(200, 40 ...
- JAVA个人小程序GUI篇-收银(标签、按钮、复选框、下拉标、文本域、表格······)
如果用eclipse需先装载windowsbuild //导入包 import java.awt.BorderLayout; import java.awt.EventQueue; import ja ...
- 【Swing/文本组件】定义自动换行的文本域
文本域组件:Swing中任何一个文本域(JTextArea)都是JTestArea类型的对象.常用的构造方法如下 public JTextArea() public JTextArea(String ...
- Swing文本域的编辑
1..setEditable(false); 设置文本域不可编辑 2..setHorizontalAlignment(JTextField.CENTER); // 设置文本的水平对齐方式 有效值包括: ...
- textarea文本域的高度随内容的变化而变化
用css控制textarea文本域的高度随内容的变化而变化,不出现滚动条. CSS代码: 复制代码 代码如下: .t_area{ width:300px; overflow-y:visible } & ...
随机推荐
- Linux入门笔记
1.Linux常用快捷键 按键 作用 Ctrl+d 键盘输入结束或退出终端 Ctrl+s 暂停当前程序,暂停后按下任意键恢复运行 Ctrl+z 将当前程序放到后台运行,恢复到前台为命令fg Ctrl ...
- 请求数据传入(SpringMVC)
1. 请求处理方法签名 Spring MVC 通过分析处理方法的签名,HTTP请求信息绑定到处理方法的相应人参中. Spring MVC 对控制器处理方法签名的限制是很宽松的,几乎可以按喜欢的任 ...
- Atlas & mysql-proxy
Atlas https://github.com/Qihoo360/Atlas https://github.com/Qihoo360/Atlas/wiki/Installing-Atlas Atla ...
- ModSecurity is an open source, cross-platform web application firewall (WAF) module.
http://www.modsecurity.org/ ModSecurity is an open source, cross-platform web application firewall ( ...
- Java正则解析HTML一例
import java.util.regex.Matcher;import java.util.regex.Pattern; public class Test { static String tes ...
- 震旦199打印机扫描A4文件
1.需要扫描的A4文件放入输稿器 2.使用数据线将打印机.电脑连接 3.在电脑中右键打印机,选择扫描功能 4.如下图,选择选项后,点击扫描即可
- 携程Apollo配置中心架构深度剖析
转自:http://www.uml.org.cn/wfw/201808153.asp 一.介绍 Apollo(阿波罗)[参考附录]是携程框架部研发并开源的一款生产级的配置中心产品,它能够集中管理应用在 ...
- logstash 使用kafka范例
写入到kafka input { stdin { } } output { kafka { bootstrap_servers => "10.0.0.200:9092" to ...
- File操作
对文件进行操作(只操作小文件) bool Exists(string path) 判断文件是否存在 FileStream Create(string path) 创建文件 void Move(stri ...
- java访问权限表
private(私有的) 默认的(什么都不写) protected(受保护的) public(公共的 ) 同一个类中 yes yes yes yes 同一个包中不同类之间 no yes yes ...