大家用过Ethereal这个网络分析软件么?现在我要做一个程序,用到的界面和它差不多,即用表格显示一行行的内容,鼠标点击某一行时,下方的面板会显示和该行相关的内容,现在不知道用JAVA该如何下手呵,请教大家了,该使用swing中的哪些组件,怎么完成呢?

解决方案 »

  1.   

    那个没用过不过用JLabel JTextArea再加些代码可以实现那样的 主要是鼠标Event
      

  2.   

    应该用JTable,不过要重写一些方法
      

  3.   


    package table;import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.table.DefaultTableModel;/**
     *
     * @author Administrator
     */
    public class NewJFrame extends javax.swing.JFrame {    /** Creates new form NewJFrame */
        DefaultTableModel myTableModel;    public NewJFrame() {
            myTableModel = new DefaultTableModel(
                    new Object[][]{
                        {"11111", "22222", "33333", "44444"},
                        {"aaaaa", "bbbbb", "ccccc", "dddddd"},
                        {"qqqqq", "wwwww", "eeeee", "rrrrr"},
                        {"yyyy", "uuuuu", "iiiii", null}
                    },
                    new String[]{
                        "Title 1", "Title 2", "Title 3", "Title 4"
                    });
            initComponents();
            jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    int i =jTable1.getSelectedRow();
                    jTextArea1.setText("you just selected row NO."+i);
                }
            });
        }    /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {        jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            jScrollPane2 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        jTable1.setModel(myTableModel);
            jScrollPane1.setViewportView(jTable1);        jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jScrollPane2.setViewportView(jTextArea1);        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(15, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                    .addContainerGap())
            );        pack();
        }// </editor-fold>    /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {
                    new NewJFrame().setVisible(true);
                }
            });
        }    // Variables declaration - do not modify
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JTable jTable1;
        private javax.swing.JTextArea jTextArea1;
        // End of variables declaration
    }