JSplitPane demo

package example; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel; public class Main { private JPanel right;
private JTree tree; public Main() {
initLeft();
initRight();
} private void initLeft() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("我的电脑");
DefaultMutableTreeNode c = new DefaultMutableTreeNode("C:");
DefaultMutableTreeNode d = new DefaultMutableTreeNode("D:");
DefaultMutableTreeNode e = new DefaultMutableTreeNode("E:"); DefaultMutableTreeNode c1 = new DefaultMutableTreeNode("file1");
DefaultMutableTreeNode c2 = new DefaultMutableTreeNode("file2");
DefaultMutableTreeNode c3 = new DefaultMutableTreeNode("file3");
DefaultMutableTreeNode c4 = new DefaultMutableTreeNode("file4"); DefaultTreeModel treeModel = new DefaultTreeModel(root);
treeModel.insertNodeInto(c, root, root.getChildCount());
treeModel.insertNodeInto(d, root, root.getChildCount());
treeModel.insertNodeInto(e, root, root.getChildCount());
treeModel.insertNodeInto(c1, c, c.getChildCount());
treeModel.insertNodeInto(c2, c, c.getChildCount());
treeModel.insertNodeInto(c3, c, c.getChildCount());
treeModel.insertNodeInto(c4, c, c.getChildCount()); tree = new JTree();
tree.setModel(treeModel);
} private void initRight() {
final Object[] columnNames = { "档案号", "姓名", "年龄", "性别", "婚姻状况", "职业", "联系电话" };
Object[][] rowData = { { "010110", "张三", "28", "男", "已婚", "教师", "13686562936" },
{ "010110", "李四", "28", "男", "已婚", "教师", "13686562936" } };
final JTable tb = new JTable(rowData, columnNames) {
private static final long serialVersionUID = 1L; public boolean isCellEditable(int row, int column) {
return false;
}
}; tb.setPreferredScrollableViewportSize(new Dimension(639, 232));
tb.setRowHeight(20);
tb.setRowSelectionAllowed(true);
tb.setSelectionBackground(Color.lightGray);
tb.setSelectionForeground(Color.white);
tb.setGridColor(Color.black);
tb.setShowGrid(true);
tb.setShowHorizontalLines(true);
tb.setShowVerticalLines(true);
tb.setBackground(Color.white);
// 添加部分2
tb.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {// 双击鼠标 if (e.getClickCount() == 2) {
int colummCount = tb.getModel().getColumnCount();
// 列数
for (int i = 0; i < colummCount; i++) {
System.out.print(tb.getModel().getColumnName(i) + ":");
System.out.print(tb.getModel().getValueAt(tb.getSelectedRow(), i).toString() + " ");
}
System.out.println();
}
}
}
});
JScrollPane pane = new JScrollPane(tb);
right = new JPanel(new BorderLayout());
right.add(pane, BorderLayout.CENTER);
right.add(new JButton("OK"), BorderLayout.SOUTH); } public static void main(String[] args)
{
Main m = new Main();
JSplitPane splitPane = new JSplitPane();// 创建一个分割容器类
splitPane.setOneTouchExpandable(true);// 让分割线显示出箭头
splitPane.setContinuousLayout(true);// 操作箭头,重绘图形
splitPane.setPreferredSize(new Dimension(800, 300));// 设置splitPane的尺寸
splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);// 设置分割线方向 splitPane.setLeftComponent(m.tree);
splitPane.setRightComponent(m.right);
splitPane.setDividerSize(10);// 分割线的宽度
splitPane.setDividerLocation(100);// 设置分割线的位置,即与左边框的距离 JFrame frame = new JFrame("JSplitPane demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(splitPane);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true); } }
JSplitPane demo的更多相关文章
- 高级组件——分割面板JSplitPane
分割面板:JSplitPane(方向),默认水平分割.JSplitPane.HORIZONTAL_SPLIT,JSplitPane.VERTICAL_SPLITJSplitPane(方向,boolea ...
- 通过一个demo了解Redux
TodoList小demo 效果展示 项目地址 (单向)数据流 数据流是我们的行为与响应的抽象:使用数据流能帮我们明确了行为对应的响应,这和react的状态可预测的思想是不谋而合的. 常见的数据流框架 ...
- 很多人很想知道怎么扫一扫二维码就能打开网站,就能添加联系人,就能链接wifi,今天说下这些格式,明天做个demo
有些功能部分手机不能使用,网站,通讯录,wifi基本上每个手机都可以使用. 在看之前你可以扫一扫下面几个二维码先看看效果: 1.二维码生成 网址 (URL) 包含网址的 二维码生成 是大家平时最常接触 ...
- 在线浏览PDF之PDF.JS (附demo)
平台之大势何人能挡? 带着你的Net飞奔吧!:http://www.cnblogs.com/dunitian/p/4822808.html#skill 下载地址:http://mozilla.gith ...
- 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo
Maven+springboot+阿里大于短信验证服务 纠结点:Maven库没有sdk,需要解决 Maven打包找不到相关类,需要解决 ps:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...
- vue双向数据绑定原理探究(附demo)
昨天被导师叫去研究了一下vue的双向数据绑定原理...本来以为原理的东西都非常高深,没想到vue的双向绑定真的很好理解啊...自己动手写了一个. 传送门 双向绑定的思想 双向数据绑定的思想就是数据层与 ...
- Android Studio-—使用OpenCV的配置方法和demo以及开发过程中遇到的问题解决
前提: 1.安装Android Studio(过程略) 2.官网下载OpenCV for Android 网址:http:opencv.org/downloads.html 我下载的是下图的版本 3. ...
- iOS之ProtocolBuffer搭建和示例demo
这次搭建iOS的ProtocolBuffer编译器和把*.proto源文件编译成*.pbobjc.h 和 *.pbobjc.m文件时,碰到不少问题! 搭建pb编译器到时没有什么问题,只是在把*.pro ...
- 钉钉开放平台demo调试异常问题解决:hostname in certificate didn't match
今天研究钉钉的开放平台,结果一个demo整了半天,这帮助系统写的也很难懂.遇到两个问题: 1.首先是执行demo时报unable to find valid certification path to ...
随机推荐
- git digest
.gitignore文件示例: .classpath .project .idea/ .settings/ target/ *~ *.iml *.log *.tmp https://zhuanlan. ...
- C++&&Mysql&&codeblocks
#include <iostream> #include <stdio.h> #include <winsock2.h> #include <mysql.h& ...
- nyist oj 311 全然背包 (动态规划经典题)
全然背包 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 直接说题意,全然背包定义有N种物品和一个容量为V的背包.每种物品都有无限件可用.第i种物品的体积是c,价值是 ...
- ON、WHERE、HAVING的差别
ON .WHERE.HAVING都能通过限制条件筛选数据,但他们的使用及其不同.以下我们来分析三者之间的差别. 1. ON 和WHERE 全部的查询都回产生一个中间暂时报表,查询结果就是从 ...
- 陈一舟《情系人人》:先搞钱,再搞人才_DoNews-IT门户-移动互联网新闻-电子商务新闻-游戏新闻-风险投资新闻-IT社交网络社区
陈一舟<情系人人>:先搞钱,再搞人才_DoNews-IT门户-移动互联网新闻-电子商务新闻-游戏新闻-风险投资新闻-IT社交网络社区 陈一舟<情系人人>:先搞钱,再搞人才
- POJ 3458 Colour Sequence(简单题)
[题意简述]:事实上题意我也没有特别看懂.可是依据它少许的题目描写叙述加上给的例子.就大胆的做了例如以下的推測: 就是说,如今给出一串字符s.然后紧接着给出可见的字符串visible还有隐藏的字符串h ...
- 30第二建筑Github Page
从我原来博客的前端传输.链接:http://www.hacke2.cn/create-github-page/ 假设中国每一个程序猿都写博客,那么中国IT届的春天就来了 有同学问我的站点是怎么创建的, ...
- Learning Cocos2d-x for WP8(5)——详解Menu菜单
原文:Learning Cocos2d-x for WP8(5)--详解Menu菜单 C#(wp7)兄弟篇Learning Cocos2d-x for XNA(5)——详解Menu菜单 菜单是游戏必不 ...
- xamarin跨平台iOS、Android 与Windows
http://xamarin.csdn.net/ Xamarin是一个行动App开发平台,提供跨平台开发能力,开发人员透过Xamarin开发工具与程序语言,即可开发出iOS.Android 与Wind ...
- Webserver管理系列:1、安装Windows Server 2008
简单了解下server: 1U: 2U: 3U: 在安装Windows Server 2008之前我们先了解下Windows Server 2008: Windows Server 2008是微软一个 ...