有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在JTable中单击鼠标时,java图像在JLabel中不可见

我正在申请一个学校项目。将照片插入SQL数据库很好,我在JTable中重命名照片,还可以在SQL编辑器中打开blob照片。无法使照片在JLabel上可见

有人能帮我吗

其目的是通过鼠标点击获得已输入信息的预览。该应用程序是一个图像库,您可以在其中输入不同的医疗设备

代码JTable

 DefaultTableModel model = (DefaultTableModel) tableDom.getModel();
    try {
        Class.forName("com.mysql.jdbc.Driver"); //database connectie maken
        try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mybrains? 
        allowMultiQueries=true&serverTimezone=America/Winnipeg&dummyparam=", "", "")) {

            String sql = "Select * from Telefonie ";  
            PreparedStatement pstmt = conn.prepareStatement(sql);
            ResultSet rs = pstmt.executeQuery(sql);
            model.setRowCount(0);
            while (rs.next()) {
                int id = rs.getInt("ID");
                String naam = rs.getString("naam"); // naam is een kollom in de database
                String model_type = rs.getString("Model_Type");
                String functionaliteit = rs.getString("Functionaliteit");
                String troubleshoot = rs.getString("Troubleshoot");
                String oplossing = rs.getString("Oplossing");
                String voorbeeld = rs.getString("Fotonaam");
                byte[] fotos = rs.getBytes("Uploadfoto");

                // ImageIcon imageicon = new ImageIcon(fotos);
                //voorbeeldfoto.setIcon(imageicon);
                //voorbeeldfoto.setIcon(foto());
                model.addRow(new Object[]{id, naam, model_type, functionaliteit, troubleshoot, 
                oplossing, voorbeeld, fotos});
            }
        } 
    } catch (ClassNotFoundException | SQLException e) {
    }

用鼠标点击编码

try {
        int i = tableDom.getSelectedRow();

        Class.forName("com.mysql.jdbc.Driver"); //database connectie maken
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mybrains? 
       allowMultiQueries=true&serverTimezone=America/Winnipeg&dummyparam=", "", "");

        String sql = "Select * from Telefonie";   
        PreparedStatement pstmt = conn.prepareStatement(sql);
        ResultSet rs = pstmt.executeQuery(sql);

        if (rs.next());

        //int i = tableDom.getSelectedRow();
        TableModel model = tableDom.getModel();
        iD.setText(model.getValueAt(i, 0).toString());
        name.setText(model.getValueAt(i, 1).toString());
        modelt.setText(model.getValueAt(i, 2).toString());
        func.setText(model.getValueAt(i, 3).toString());
        oplos.setText(model.getValueAt(i, 4).toString());
        troubl.setText(model.getValueAt(i, 5).toString());
        photoNaam.setText(model.getValueAt(i, 6).toString());
        byte[] voorbeeldfoto = rs.getBytes("Uploadfoto");

        JLabel image1 = (JLabel) model.getValueAt(i, 8);
        ImageIcon image1Icon = (ImageIcon) image1.getIcon();
        voorbeeldfoto.setIcon(image1Icon);
    } catch (ClassNotFoundException | SQLException ex) {
        JOptionPane.showMessageDialog(rootPane, name);

    }
}                            

共 (0) 个答案