今天开始写技术博客,说实话,本没有什么技术,说是总结也好,说是分享也罢,总之是想自己有意识的做一些事情,作为一名即将毕业的大学生,总是想以最好的状态,去面向社会,今天就是我准备好了的时候,本人将技术博客发布在新浪博客以及博客园,新浪博客,不仅发布技术博客,还会写一些个人随笔和感悟。而博客园,全是技术干货。希望大家视自己的情况关注。感谢么么哒!

技术博客,每周一篇。周一发布。

至于其他,我高兴就好...0.0...

一、Swing中JTree

  1.  
  1. package com.no1;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Dimension;
  5.  
  6. import javax.swing.JFrame;
  7. import javax.swing.JOptionPane;
  8. import javax.swing.JPanel;
  9. import javax.swing.JTree;
  10. import javax.swing.UIManager;
  11. import javax.swing.event.TreeSelectionEvent;
  12. import javax.swing.event.TreeSelectionListener;
  13. import javax.swing.tree.DefaultMutableTreeNode;
  14.  
  15. public class JTreeExample extends JFrame {
  16.  
  17. /**
  18. *
  19. */
  20. private static final long serialVersionUID = 1L;
  21. private JPanel Jp;
  22.  
  23. public static void main(String[] args) {
  24.  
  25. @SuppressWarnings("unused")
  26. JTreeExample Je = new JTreeExample();
  27.  
  28. }
  29.  
  30. // 构造函数
  31. public JTreeExample() {
  32. this.setTitle("JTree实例");
  33. //
  34. this.setSize(200, 500);
  35.  
  36. // 窗口自动居中
  37. this.setLocationRelativeTo(null);
  38.  
  39. this.setLayout(new BorderLayout());
  40.  
  41. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  42. // 保持Window窗体基本风格
  43. try {
  44. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  45. } catch (Exception err) {
  46. err.printStackTrace();
  47. }
  48. // 不能最大化
  49. this.setResizable(false);
  50. this.init();
  51. this.setVisible(true);
  52.  
  53. }
  54.  
  55. public void init() {
  56. // 实例化JPanel对象
  57. Jp = new JPanel();
  58. // 设置大小
  59. Jp.setPreferredSize(new Dimension(200, 400));
  60. // 为面板设置布局方式
  61. Jp.setLayout(null);
  62. // Jp.setBackground(Color.BLACK);
  63.  
  64. // 创造默认节点
  65. DefaultMutableTreeNode note1 = new DefaultMutableTreeNode("中国");
  66. // 将实例化的节点加入以上节点
  67. note1.add(new DefaultMutableTreeNode("北京"));
  68. note1.add(new DefaultMutableTreeNode("上海"));
  69. DefaultMutableTreeNode note2 = new DefaultMutableTreeNode("美国");
  70. note2.add(new DefaultMutableTreeNode("华盛顿"));
  71. note2.add(new DefaultMutableTreeNode("纽约"));
  72.  
  73. DefaultMutableTreeNode top = new DefaultMutableTreeNode("国家");
  74. // 又将以上两个节点,note1与弄=note2加入到top节点
  75. top.add(note1);
  76. top.add(note2);
  77. // 实例化JTree,并将top加入到JTree中
  78. final JTree Jtree = new JTree(top);
  79. // 设置Jtree大小
  80. Jtree.setBounds(0, 0, 200, 300);
  81. // 将Jtree入到面板中
  82. Jp.add(Jtree);
  83. // 将面板加入JFrame
  84. this.add(Jp, BorderLayout.WEST);
  85.  
  86. // 为节点设置点击事件
  87. Jtree.addTreeSelectionListener(new TreeSelectionListener() {
  88.  
  89. @Override
  90. public void valueChanged(TreeSelectionEvent arg0) {
  91.  
  92. /*
  93. * 返回当前选择的第一个节点中的最后一个路径组件。API原话
  94. * 就是返回你点击的节点
  95. */
  96. DefaultMutableTreeNode node = (DefaultMutableTreeNode) Jtree.getLastSelectedPathComponent();
  97.  
  98. if (node == null) {
  99. return;
  100. }
  101.  
  102. // 判断是否是一个子节点
  103. if (node.isLeaf()) {
  104. if ((node.toString()).equals("北京")) {
  105.  
  106. JOptionPane.showMessageDialog(null, "你点击的是北京");
  107.  
  108. } else if ((node.toString()).equals("纽约")) {
  109.  
  110. JOptionPane.showMessageDialog(null, "你点击的是纽约");
  111.  
  112. }
  113. }
  114. //如果为父节点添加事件,直接这样
  115. if (node.toString().equals("中国")) {
  116.  
  117. JOptionPane.showMessageDialog(null, "你点击的是中国");
  118.  
  119. }
  120.  
  121. }
  122. });
  123.  
  124. }
  125.  
  126. }
  1.  
  1.  

效果图

二、Swing组件之JTablePane选项卡

  1. package com.no1;
  2.  
  3. import java.awt.Font;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JPanel;
  7. import javax.swing.UIManager;
  8. import javax.swing.JTabbedPane;
  9.  
  10. public class JTabbedPaneExample extends JFrame{
  11.  
  12. private JTabbedPane aa ;
  13. private JPanel Jp01,Jp02,Jp03;
  14.  
  15. private static final long serialVersionUID = 1L;
  16.  
  17. public static void main(String[] args) {
  18. @SuppressWarnings("unused")
  19. JTabbedPaneExample a =new JTabbedPaneExample();
  20.  
  21. }
  22. public JTabbedPaneExample(){
  23.  
  24. this.setTitle("JTablePane实例");
  25. //
  26. this.setSize(500, 300);
  27.  
  28. // 窗口自动居中
  29. this.setLocationRelativeTo(null);
  30.  
  31. this.setLayout(null);
  32.  
  33. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34. // 保持Window窗体基本风格
  35. try {
  36. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  37. } catch (Exception err) {
  38. err.printStackTrace();
  39. }
  40. // 不能最大化
  41. this.setResizable(false);
  42. this.init();
  43.  
  44. this.setVisible(true);
  45.  
  46. }
  47. private void init(){
  48.  
  49. aa =new JTabbedPane(JTabbedPane.TOP);
  50. //给JTabbedPane设置大小
  51. aa.setBounds(0, 0, 500, 300);
  52. Jp01 =new JPanel();
  53. Jp02 =new JPanel();
  54. Jp03 =new JPanel();
  55.  
  56. Jp01.setBounds(0, 0, 500, 300);
  57. Jp02.setBounds(0, 0, 500, 300);
  58. Jp03.setBounds(0, 0, 500, 300);
  59. //将三个面板加入到JTabbedPane上
  60. aa.addTab("面板一", Jp01);
  61. aa.addTab("面板二", Jp02);
  62. aa.addTab("面板三", Jp03);
  63. //设置字体为宋体,不加粗(加粗为1),字号18
  64. aa.setFont(new Font("宋体", 0, 18));
  65. //添加到JFrame内容面板上,也可以直接this.add(aa);
  66. this.getContentPane().add(aa);
  67. //初始显示面板一
  68. aa.setSelectedIndex(0);
  69.  
  70. }
  71.  
  72. }

预览效果

好了,接下来看你们的了。

Swing组件Jtree,JTablePane选项卡运用的更多相关文章

  1. java中经常使用的Swing组件总结

    1.按钮(Jbutton) Swing中的按钮是Jbutton,它是javax.swing.AbstracButton类的子类,swing中的按钮可以显示图像,并且可以将按钮设置为窗口的默认图标,而且 ...

  2. JAVA Swing 组件演示***

    下面是Swing组件的演示: package a_swing; import java.awt.BorderLayout; import java.awt.Color; import java.awt ...

  3. Swing组件都采用MVC设计模式

    Swing组件都采用MVC(Model-View-Controller,既模型-视图-控制器)设计模式,从而可以实现GUI组件的显示逻辑和数据逻辑的分离,允许程序员自定义Render来改变GUI组件的 ...

  4. 自学电脑游戏第三天(Swing组件)

    Swing组件 1.按钮(Jbutton) 示例:选择用户所喜欢的城市. import java.awt.*; import java.awt.event.*; import javax.swing. ...

  5. Java-GUI编程之Swing组件

    目录 为组件设置边框 使用JToolBar创建工具条 JColorChooser和JFileChooser JColorChooser JFileChooser JOptionPane 基本概述 四种 ...

  6. 详解Swing中JTree组件的功能

    JTree组件是另外一个复杂组件,它不像 JTable 那样难用,但是也不像 JList 那么容易.使用 JTree 时麻烦的部分是它要求的数据模型. JTree组件的功能来自树的概念,树有分支和叶子 ...

  7. Java Swing 树状组件JTree的使用方法(转)

    树中特定的节点可以由 TreePath(封装节点及其所有祖先的对象)标识,或由其显示行(其中显示区域中的每一行都显示一个节点)标识.展开 节点是一个非叶节点(由返回 false 的 TreeModel ...

  8. Swing 组件焦点设置

    在Swing中,焦点默认是在第一个组件上,所以在项目中想将焦点设置在其他的组件上,如JTextField!但通过requestFocus()方法不起作用,有人提供以下解决方法: 全部初始化之后,jTe ...

  9. Swing组件 创建窗口应用

    package com.swing; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt. ...

随机推荐

  1. 获取设备上全部系统app信息

    在获取android设备的全部程序信息一文中介绍了获取手机上全部app信息的方法,以下介绍过滤掉系统app的方法: MainActivity: package com.home.getsysapp; ...

  2. maven学习(二)

    为了兼容之前基于ant构建的项目发布包结构,在基于maven做构建的时候,需要自定义打包方式. maven的maven-assembly-plugin插件支持任意格式的打包,比如:dir,zip等形式 ...

  3. Vesions ignore & ld: library not found for -l...

    1.递归删除指定目录下的 .git..svn 文件 find . -name .git | xargs rm -fr find . -name .svn | xargs rm -rf 第一条倒还不常用 ...

  4. 各种电子面单_Api接口

    电子面单是一种通过热敏纸打印输出纸质物流面单的物流服务.通过热感应显示文字,打印速度比传统针式打印速度提升4~6倍.电子面单以接口形式嵌入到自己的系统.网站上,可以在自己的平台操作打印电子面单.   ...

  5. Recommended you 3 most popular Nissan pincode calculators

    Have you still felt confused on how to choose a satisfactory Nissan pin code calculator in the marke ...

  6. Hill Climber and Random Walk

  7. Windows Azure 微软公有云体验(二) 存储成本比较分析

    Windows Azure 微软公有云已经登陆中国有一段时间了,现在是处于试用阶段,Windows Azure的使用将会给管理信息系统的开发.运行.维护带来什么样的新体验呢? Windows Azur ...

  8. 在vs中跑动kdtree 和 bbf

    这两天的学习模型都来自:http://blog.csdn.net/masibuaa/article/details/9246493 所谓的bbf 英文名字叫做best bin first 译名:最优节 ...

  9. windows下安装swoole。

    服务器是用了Linux环境,所以安装swoole的过程只要看看文档就好了. 由于编写代码环境是在windows上,需要在windows上安装swoole.以便测试. 好了废话不多说,我们看官网文档解决 ...

  10. [转]Response.AddHeader 文本下载

    本文转自:http://hi.baidu.com/yuxi981/item/7c617fc41b03ad60f6c95d30 Response.AddHeader实现下载     /// <su ...