你这两个table可以动态生成呀
两个按扭提交的时候,给它分配不同的参数,server根据这个参数来选择生成相应的table

解决方案 »

  1.   

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;public class SimpleTableDemo extends JFrame implements ActionListener {

    private JButton button1 = new JButton("第一个表");
    private JButton button2 = new JButton("第二个表");
    private Container panel;
        JScrollPane scrollPane1 ;
        JScrollPane scrollPane2 ;
    static  SimpleTableDemo frame;
        public SimpleTableDemo() {        super("SimpleTableDemo");        Object[][] data1 = {
                {"Mary", "Campione", 
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml", 
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Chasing toddlers", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Angela", "Lih",
                 "Teaching high school", new Integer(4), new Boolean(false)}
            };
            Object[][] data2 = {
                {"Mary2", "Campione", 
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison2", "Huml", 
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy2", "Walrath",
                 "Chasing toddlers", new Integer(2), new Boolean(false)},
                {"Sharon2", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Angela2", "Lih",
                 "Teaching high school", new Integer(4), new Boolean(false)}
            };        String[] columnNames1 = {"First Name", 
                                    "Last Name",
                                    "Sport",
                                    "# of Years",
                                    "Vegetarian"};
            String[] columnNames2 = {"First Name2", 
                                    "Last Name2",
                                    "Sport2",
                                    "# of Years2",
                                    "Vegetarian2"};        final JTable table1 = new JTable(data1, columnNames1);
            final JTable table2 = new JTable(data2, columnNames2);        //Create the scroll pane and add the table to it. 
             scrollPane1 = new JScrollPane(table1);
             scrollPane2 = new JScrollPane(table2);        //Add the scroll pane to this window.
    panel = (JPanel)this.getContentPane();
    panel.setLayout(new GridLayout(3,1));
            panel.add(scrollPane1);
    button1.setActionCommand("Button1");
    button2.setActionCommand("Button2");

    panel.add(button1);
    panel.add(button2);
    button1.addActionListener(this);
    button2.addActionListener(this);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });
        }
    public void actionPerformed(ActionEvent e) 
    { if ("Button1".equals(e.getActionCommand())) 
    {
    frame.setVisible(false);
    panel.remove(scrollPane2);
    panel.add(scrollPane1);
    frame.setVisible(true); } 
    else 
    {
    frame.setVisible(false);
    panel.remove(scrollPane1);
    panel.add(scrollPane2);
    frame.setVisible(true);
    }
    }
        public static void main(String[] args) {
            frame = new SimpleTableDemo();
            frame.pack();
            frame.setVisible(true);
        }
    }
    写了一个简单的例子,你把Layout重新设定好了就可以了
      

  2.   

    分别将两个table放在两个panel上,然后将这两个panel采用CardLayout通过设置panel的可见性来控制显示那一个
      

  3.   

    楼主说的form是指网页中的吧?
    呵呵
      

  4.   

    在网页上应该也是可以的,你可以这样吧
    <div id="test"></div>在button1的click的时候生成table
    window.test.innerHTML=showTable1();
    在button2的click的时候生成table
    window.test.innerHTML=showTable2();
      

  5.   

    我指的是在jsp页面中如何控制
      

  6.   

    使用样式表:
    先将数据分别写入两个table(但页面加载时可以隐藏)
    <table id=tb1 style="display:none">.....</table>
    <table id=tb2 style="display:none">.....</table>
    再利用javascript脚本控制table的显示
    显示第一个table:
    tb1.style.display='block';
    隐藏第一个table,显示第二个table:
    tb1.style.display='none';
    tb2.style.display='block';
      

  7.   

    <input type="button" value="Hidden" onClick="temp.style.display=='none'?temp.style.display='':temp.style.display='none';
    this.value=='Hidden'?this.value='Show':this.value='Hidden'"><p>
    <span id="temp">
    <input type="button" value="hidden me!" name="btn"><p>
    <table border="1">
    <tr>
    <td>hidden me!</td>
    <td>hidden me!</td>
    </tr>
    </table>
    </span>
      

  8.   

    <input type="button" onclick="document.all.btn.style.display = 'none';document.all.tbl.style.display='none';">
    <input type="button" name="btn">
    <table id="tbl">
    adsfasdfsadf
    </table>
      

  9.   

    来晚一步,呵呵上面说得都不错啦.
    给每个table定义他们的id然后在button里面写onclick事件,对每个table的style.display属性做改变,
    该变成 none ,就是不显示,这时整个table都不见,并且不占网页的位置,
    变成block或者 ''就是显示.