随风而醒 2017-04-28 03:08 采纳率: 0%
浏览 1983
已结题

Java中如何根据我点击的按钮呈现不同的JTable样式(一个JFrame中)?

我现在的需求是,通过点击上面不同的按钮,下方出现对应的表格。
界面
界面程序代码:首先初始化了一个表格

 // 图表窗口
    public void tableInformation() {

        JPanel toolBar = new JPanel();
        toolBar.add(this.loadFileBtn);
        toolBar.add(this.transferBtn);
        toolBar.add(this.selectBtn);
        toolBar.add(this.functionNumBtn);
        toolBar.add(this.scoreBtn);
        toolBar.add(this.noScoreBtn);

        this.add(toolBar, BorderLayout.NORTH);
        this.loadFileBtn.addActionListener(this);
        this.transferBtn.addActionListener(this);
        this.selectBtn.addActionListener(this);
        this.functionNumBtn.addActionListener(this);
        this.scoreBtn.addActionListener(this);
        this.noScoreBtn.addActionListener(this);

        this.tableModel = new DefaultTableModel(new UserList().userInfo, new UserList().titles);

        this.table = new JTable(this.tableModel);

        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

        table.setPreferredScrollableViewportSize(new Dimension(150, 0));

        table.getTableHeader().setReorderingAllowed(false);

        table.enable(false);

        JScrollPane scr = new JScrollPane(this.table);

        this.add(scr, BorderLayout.CENTER);
        this.remove(scr);

        //
        while (this.tableModel.getRowCount() > 0) {
            this.tableModel.removeRow(this.tableModel.getRowCount() - 1);
        }
    }

现在我想做的是:当点击“统计操作数”按钮时,会出现另一个表格样式

按钮代码:

 else if (e.getSource() == this.functionNumBtn) {
            //这里如何写?



        }

补充数据源代码:

 class UserList extends AbstractTableModel {
    public String[] titles = { "username", "udate", "utime", "tcode" };
    public Object[][] userInfo = {}; //

    public int getRowCount() {
        return 0;
    }

    public int getColumnCount() {
        return 0;
    }

    //
    @Override
    public Object getValueAt(int arg0, int arg1) {
        return null;
    }
}

请教如何做?(代码中的空格部分)

  • 写回答

1条回答 默认 最新

  • 乔小南丶 2017-04-28 06:09
    关注

    首先写好你需要的table
    有几个写几个 每个的style的display都是隐藏的
    通过点击按钮调用js 来改变table的display
    点1 就把除了1的display变成隐藏 1显示
    点2 类推

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示