Realize the linkage between JTree and jtable, and the increase and deletion of jtable data

Source: Internet
Author: User

In the homework have encountered about JTree and jtable linkage problem, and later on the Internet to check a lot of, are not written all the way, so wrote a small procedure for the consolidation and for the needs of the people reference

One implementation function

1 Display the data in the corresponding table

2 realizes the linkage between JTree and jtable.

3 Add and delete a row for the corresponding table table (click one line to delete)

Two code implementation

1 JTree and jtable panel code implementation

[Java]  View plain copy package library;      import java.awt.borderlayout;   import java.awt.dimension;   import java.awt.flowlayout;   import  java.awt.event.*;   import java.io.bufferedreader;   import java.io.File;    import java.io.filereader;   import java.io.ioexception;      import javax.swing.borderfactory;   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.event.*;   import  javax.swing.table.defaulttablemodel;   import javax.swing.tree.defaultmutabletreenode;    IMPORT JAVAX.SWING.TRee. treepath;   import javax.swing.tree.treeselectionmodel;  /**   *  @author  HuangRong   * Date 2013/11/18   *    */   Public  class TreeTableText extends JFrame{          /**        *  @param  args       */       private JPanel panel;       public jtable  table;       private JButton but_Add,but_Delect;       private JScrollPane treePane;       private  JScrollPane tablePane;       private object[] node={" Borrow Books Student Information "," Borrow books Student Information "};       private defaultmutabletreenode node1, node2,top; &nbsp     private DefaultTableModel tableModel1,tableModel2;        private JSplitPane split;       private String[]  colum1 = {"Name", "School Number", "Telephone", "Library Time"};       private String[][]  data1 = {{  "Lee",  "1108010 ...", 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.