简单学生管理系统中用到的一些知识点

本文介绍如何使用Java实现表格创建、数据更新及图片的缩放显示等实用功能,并提供了数据库中图片的存储与读取方法。

一、表格的创建

/**

     * 表格中的数据

     */

    private Vector<Object> data;

    /**

     * 列名

     */

    private Vector<String> columnNames;

 

tableModel=new DefaultTableModel(data,columnNames);

       table=new JTable(tableModel);

//设置初始表格视口的大小

       table.setPreferredScrollableViewportSize(new Dimension(450,250));

二、清空表格中的数据

//清空数据

              tableModel.getDataVector().clear();

              tableModel.fireTableDataChanged();

三、图片缩放大小

    ImageIcon icon=new ImageIcon(imagePath);

    icon.setImage(icon.getImage().getScaledInstance(50, 50,Image.SCALE_DEFAULT));

                     imageLabel.setIcon(icon);

 

四、数据库中存图片

 

InputStream in;

if (null != in)

                  pstm.setBinaryStream(5, in, in.available());

              else{

                  pstm.setBinaryStream(5, in,0);

              }

五、数据库中取图片显示

if (null != in)

                  pstm.setBinaryStream(5, in, in.available());

              else{

                  pstm.setBinaryStream(5, in,0);

              }

if(in!=null){

                     byte [] buf=new byte[in.available()];

                     in.read(buf);

                     ImageIcon icon=new ImageIcon(buf);

                     icon.setImage(icon.getImage().getScaledInstance(50, 50,Image.SCALE_DEFAULT));

                     imageLabel.setIcon(icon);

                     imageLabel.setText("照片 :       ");

                  }else{

                     imageLabel.setText("照片: 没上传照片 ");

                  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值