Insert And Display User Input On JTable – Java GUI Swing Tutorial – Netbeans IDE

Insert And Display User Input On JTable – Java GUI Swing Tutorial – Netbeans IDE

ADD, EDIT,DELETE,IMPORT,EXPORT,PRINT,DISPLAY ON DATAGRIDVIEW (JAVA GUI)

Insert And Display User Input On JTable - Java GUI Swing Tutorial - Netbeans IDE
Insert And Display User Input On JTable – Java GUI Swing Tutorial – Netbeans IDE

Insert And Display User Input On JTable – Java GUI Swing Complete Tutorial – Netbeans IDE

Video Tutorial

Java GUI Swing Tutorial – Netbeans IDE (Project Source Code) – Graphical User Interface (GUI) Complete Beginners Guide

Step By Step Graphical User Interface (GUI) Complete Beginners Guide – Java GUI Swing Complete Tutorial – Netbeans IDE

Video Playlist

What’s covered in this guide :

  1. how to Display the information of a JTable row when selected.
  2. how to display selected row in Jtable.
  3. How to add radio button to buttongroup netbeans.
  4. how to add add checkbox to buttongroup netbeans.
  5. how to get selected radio button value in java
  6. how to get selected checkbox value in java.
  7. how to add check boxes value in in jtable.
  8. how to add radio button value in in jtable.
  9. how to display selected jtable row on jtextbox
  10. how to display selected jtable row on jcombobox
  11. how to display selected jtable row on jradiobutton
  12. how to display selected jtable row on jcheckbox
  13. how to display imageicon in java jtable cell
  14. How to add ImageIcon to a JLabel
  15. how to display imageicon in java jlabel
  16. how to display image in jtable cell in java
  17. how to resize image in java swing
  18. how to browse image in java swing
  19. how to select image from your computer in java
  20. how to display image using jfilechooser in java swing
  21. how to Use JFileChooser to open and display an image
  22. How To Browse Image File And Display It Using JFileChooser
  23. How to add image in a JTable cell Java
  24. how to display one radiobutton at a time in java
  25. how to display one checkbox at a time in java
  26. how to reset radio button in java
  27. how to reset checkbox in java
  28. how to reset textbox in java
  29. how to reset combobox button in java
  30. how to check if input field is empty java
  31. how to display selected jtable row on input fields in java
  32. how to scale image in java
  33. how to change default error handling (Logging and Exception Handling in NetBeans) in netbeans java
  34. How To Move JTable Selected Rows Up And Down In Java Using NetBeans
  35. How to add image in a JTable cell
  36. How to clear or Remove an Image from Jlabel
  37. how to set background color of jframe in swing in java
  38. how to add external jar file (libraries) in netbeans project
  39. how to export jtable data to excel in java netbeans
  40. How To Import Excel in Java JTable (GUI) Swing Application Tutorial – Netbeans
  41. How To Open A New Jframe On Button Click In Netbeans
  42. How to position the form in the center screen?
  43. How to show JTable Selected Row Data In Another JFrame.
  44. how to delete selected row from jtable in netbeans
  45. How To Clear Java Jtable Rows
  46. How To Delete All The Rows In A Jtable.
  47. How To Remove all rows from jtable
  48. how to print jtable data in java swing
  49. How To add next(move down) and previous(move up) row buttons.
  50. How To Change Image column minimum width and maximum width
  51. How To change JPanel background color.
  52. How To display selected row on another form with input boxes.
  53. How To add icons to buttons.
  54. How To Add Image Or Icons To Button Java Netbeans.

AddDataToJTable.java Source Code


/*
 * Java GUI Swing Tutorial - Netbeans IDE (Project Source Code) - Graphical User Interface (GUI) Complete Beginners Guide (Demo)
 */
package AddDataToJTable;

import java.awt.Component;
import java.awt.Image;
import java.awt.print.PrinterException;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 *
 * @author Genuine
 */
public class AddDataToJTable extends javax.swing.JFrame {

    /**
     * Creates new form AddDataToJTable
     */
    public AddDataToJTable() {
        initComponents();
        //Calling method/function to add column header to jtable
        addTableHeader();
    }

    ViewSelectedRowJFrame viewSelectedRow = new ViewSelectedRowJFrame();
    SelectedRowsJFrameForm selectedRowsJFrameForm = new SelectedRowsJFrameForm();

    /**
     * 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() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextFieldName = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jRadioButtonMale = new javax.swing.JRadioButton();
        jRadioButtonFemale = new javax.swing.JRadioButton();
        jCheckBoxJava = new javax.swing.JCheckBox();
        jCheckBoxPHP = new javax.swing.JCheckBox();
        jComboBoxSubjects = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jLabelImage = new javax.swing.JLabel();
        jButtonBrowseImage = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButtonPrint = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "null"
            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jTextFieldName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNameActionPerformed(evt);
            }
        });

        jLabel1.setText("Name");

        buttonGroup1.add(jRadioButtonMale);
        jRadioButtonMale.setText("Male");

        buttonGroup1.add(jRadioButtonFemale);
        jRadioButtonFemale.setText("Female");

        buttonGroup2.add(jCheckBoxJava);
        jCheckBoxJava.setText("Java");

        buttonGroup2.add(jCheckBoxPHP);
        jCheckBoxPHP.setText("PHP");

        jComboBoxSubjects.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Computer Science", "Information Technology", "Business Information Technology" }));

        jButton1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Authentic\\Documents\\NetBeansProjects\\How-to-show-JTable-Selected-Row-Data-In-Another-JFrame\\Icons\\plus-1.png")); // NOI18N
        jButton1.setText("Add Data");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButtonBrowseImage.setIcon(new javax.swing.ImageIcon("C:\\Users\\Authentic\\Documents\\NetBeansProjects\\How-to-show-JTable-Selected-Row-Data-In-Another-JFrame\\Icons\\landscape-24.png")); // NOI18N
        jButtonBrowseImage.setText("Browse //");
        jButtonBrowseImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBrowseImageActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon("C:\\Users\\Authentic\\Documents\\NetBeansProjects\\How-to-show-JTable-Selected-Row-Data-In-Another-JFrame\\Icons\\up-arrow.png")); // NOI18N
        jButton2.setText("Move Up");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon("C:\\Users\\Authentic\\Documents\\NetBeansProjects\\How-to-show-JTable-Selected-Row-Data-In-Another-JFrame\\Icons\\down-arrow.png")); // NOI18N
        jButton3.setText("Move Down");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon("C:\\Users\\Authentic\\Documents\\NetBeansProjects\\How-to-show-JTable-Selected-Row-Data-In-Another-JFrame\\Icons\\clear.png")); // NOI18N
        jButton4.setText("Clear");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon("C:\\Users\\Authentic\\Documents\\NetBeansProjects\\How-to-show-JTable-Selected-Row-Data-In-Another-JFrame\\Icons\\list.png")); // NOI18N
        jButton5.setText("View Selected Row");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setIcon(new javax.swing.ImageIcon("C:\\Users\\Authentic\\Documents\\NetBeansProjects\\How-to-show-JTable-Selected-Row-Data-In-Another-JFrame\\Icons\\excel.png")); // NOI18N
        jButton6.setText("Export (Excel)");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setIcon(new javax.swing.ImageIcon("C:\\Users\\Authentic\\Documents\\NetBeansProjects\\How-to-show-JTable-Selected-Row-Data-In-Another-JFrame\\Icons\\excel.png")); // NOI18N
        jButton7.setText("Import (Excel)");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setIcon(new javax.swing.ImageIcon("C:\\Users\\Authentic\\Documents\\NetBeansProjects\\How-to-show-JTable-Selected-Row-Data-In-Another-JFrame\\Icons\\x-button.png")); // NOI18N
        jButton8.setText("Delete Selected  Row");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton9.setIcon(new javax.swing.ImageIcon("C:\\Users\\Authentic\\Documents\\NetBeansProjects\\How-to-show-JTable-Selected-Row-Data-In-Another-JFrame\\Icons\\list.png")); // NOI18N
        jButton9.setText("View Selected Rows");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButtonPrint.setIcon(new javax.swing.ImageIcon("C:\\Users\\Authentic\\Documents\\NetBeansProjects\\How-to-show-JTable-Selected-Row-Data-In-Another-JFrame\\Icons\\printer-2.png")); // NOI18N
        jButtonPrint.setText("Print");
        jButtonPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPrintActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jComboBoxSubjects, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButtonMale)
                            .addComponent(jCheckBoxJava))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBoxPHP)
                            .addComponent(jRadioButtonFemale)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButtonPrint, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelImage, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonBrowseImage, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(15, 15, 15))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 742, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel1)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jRadioButtonMale)
                                .addComponent(jRadioButtonFemale))
                            .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jCheckBoxJava)
                                .addComponent(jCheckBoxPHP)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxSubjects, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelImage, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButtonBrowseImage, javax.swing.GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE)
                            .addComponent(jButtonPrint, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(61, 61, 61)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>                        

    private void jTextFieldNameActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
    }                                              
    DefaultTableModel model;
    String name = "";
    String gender = "";
    String programmingLanguage = "";
    String Subject = "";
    String selectedImagePath = "";
    String excelImagePath = "";
//    byte imageJtable = new Byte(1024);

//Adding table headers
    public void addTableHeader() {
        model = (DefaultTableModel) jTable1.getModel();
        Object[] newIdentifiers = new Object[]{"Name", "Gender", "Language", "Subject", "Image"};
        model.setColumnIdentifiers(newIdentifiers);
        //Get Image column and override  TableCellRenderer class component method (getTableCellRendererComponent)
        jTable1.getColumn("Image").setCellRenderer(new myTableCellRenderer());

    }

    private void populateInputfields() {
        //        Display data from jtable in input fields
        int selectedRow = jTable1.getSelectedRow();

        jTextFieldName.setText(model.getValueAt(selectedRow, 0).toString());
        String tableGender = model.getValueAt(selectedRow, 1).toString();
        if (tableGender.equals("Male")) {
            jRadioButtonMale.setSelected(true);
        } else if (tableGender.equals("Female")) {
            jRadioButtonFemale.setSelected(true);
        }
        String checkPLanguage = model.getValueAt(selectedRow, 2).toString();

        if (checkPLanguage.equals("Java")) {
            jCheckBoxJava.setSelected(true);
        } else if (checkPLanguage.equals("PHP")) {
            jCheckBoxPHP.setSelected(true);
        }

        String comboSub = model.getValueAt(selectedRow, 3).toString();
        for (int i = 0; i < jComboBoxSubjects.getItemCount(); i++) {
            if (jComboBoxSubjects.getItemAt(i).toString().equalsIgnoreCase(comboSub)) {
                jComboBoxSubjects.setSelectedIndex(i);
            }
        }

        //The image is stored as ImageIcon in jlabel
        //The image is stored in the fourth column
        JLabel imageJl = (JLabel) model.getValueAt(selectedRow, 4);
        //Retrieving image icon from jlabel
        //Store image icon In ImageIcon type Variable
        ImageIcon imageJLIcon = (ImageIcon) imageJl.getIcon();
        //Resize image to fit to jlable
        Image imageJLFit = imageJLIcon.getImage().getScaledInstance(jLabelImage.getWidth(), jLabelImage.getHeight(), Image.SCALE_SMOOTH);
        //Display selected image on jlabel
        jLabelImage.setIcon(new ImageIcon(imageJLFit));

    }

    class myTableCellRenderer implements TableCellRenderer {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

//            Change Image column minimum width and maximum width
            TableColumn tb = jTable1.getColumn("Image");
            tb.setMaxWidth(60);
            tb.setMinWidth(60);
            jTable1.setRowHeight(60);
            return (Component) value;

        }

    }


    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:

    }                                     

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        name = jTextFieldName.getText();
        if (jRadioButtonMale.isSelected()) {
            gender = "Male";
        } else if (jRadioButtonFemale.isSelected()) {
            gender = "Female";
        }

        if (jCheckBoxJava.isSelected()) {
            programmingLanguage = "Java";
        } else if (jCheckBoxPHP.isSelected()) {
            programmingLanguage = "PHP";
        }

        Subject = jComboBoxSubjects.getSelectedItem().toString();

        JLabel imageLabel = new JLabel();
        ImageIcon imageicon = new ImageIcon(selectedImagePath);
        //Resize image to fixed dimensions 60 * 60 (width and height).
        Image imageIc = imageicon.getImage().getScaledInstance(60, 60, Image.SCALE_SMOOTH);

//        Set Description
        ImageIcon excelSetDescription = new ImageIcon(imageIc);
        excelSetDescription.setDescription(selectedImagePath);
        //Storing imageicon in a jlabel
        imageLabel.setIcon(excelSetDescription);

        //Checking if one or more field is empty
        if (name.isEmpty() || gender.isEmpty() || programmingLanguage.isEmpty() || Subject.isEmpty() || imageIc == null) {
            JOptionPane.showMessageDialog(null, "One Or More Fields Are Empty");
        } else {
//            JOptionPane.showMessageDialog(null, "All Fields are filled");
            //Adding entered data to jtable

            model.addRow(new Object[]{name, gender, programmingLanguage, Subject, imageLabel});
            JOptionPane.showMessageDialog(null, "Data Inserted");
            //clear fields after inserting the data
            clearFields();
        }

    }                                        

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:     

        //Display Selected row data in input field
        populateInputfields();

    }                                    

    private void jButtonBrowseImageActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        // TODO add your handling code here:
//        Setting default browser location
        JFileChooser browseImageFile = new JFileChooser("C:\\Users\\Public\\Pictures\\Sample Pictures");
        //Filter image extensions
        FileNameExtensionFilter fnef = new FileNameExtensionFilter("IMAGES", "png", "jpg", "jpeg");
        browseImageFile.addChoosableFileFilter(fnef);
        int showOpenDialogue = browseImageFile.showOpenDialog(null);

        if (showOpenDialogue == JFileChooser.APPROVE_OPTION) {
            File selectedImageFile = browseImageFile.getSelectedFile();
            selectedImagePath = selectedImageFile.getAbsolutePath();
            JOptionPane.showMessageDialog(null, selectedImagePath);
            //Display image on jlable
            ImageIcon ii = new ImageIcon(selectedImagePath);
//            Resize image to fit jlabel
            Image image = ii.getImage().getScaledInstance(jLabelImage.getWidth(), jLabelImage.getHeight(), Image.SCALE_SMOOTH);

            jLabelImage.setIcon(new ImageIcon(image));
        }
    }                                                  

    //Move up button
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        //Get jtable selected row
        int currentlySelectedRow = jTable1.getSelectedRow();
        if (currentlySelectedRow > 0) {
//            Substact one (1) from current row to move upwards
            model.moveRow(currentlySelectedRow, currentlySelectedRow, currentlySelectedRow - 1);
            jTable1.getSelectionModel().setSelectionInterval(currentlySelectedRow - 1, currentlySelectedRow - 1);

        } else {
            JOptionPane.showMessageDialog(null, "You have reached the end!! Click move down button - to move downwards");
        }

    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:

        //Get jtable selected row
        int currentlySelectedRow = jTable1.getSelectedRow();
        if (currentlySelectedRow < jTable1.getRowCount() - 1) {
//            Add one (1) To current row to move downwards
            model.moveRow(currentlySelectedRow, currentlySelectedRow, currentlySelectedRow + 1);
            jTable1.getSelectionModel().setSelectionInterval(currentlySelectedRow + 1, currentlySelectedRow + 1);

        } else {
            JOptionPane.showMessageDialog(null, "You have reached the end!! Click move up button - to move upwards");
        }


    }                                        

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        //Display Selected row data in input field
    }                                     

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        viewSelectedRow.setVisible(true);
        //prevent the frame from closing the parent frame
        viewSelectedRow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

//        Get selected row
        int selectedRowForNewJframe = jTable1.getSelectedRow();

//        check if the row is selected
        if (selectedRowForNewJframe == -1) {
            //display error message
            viewSelectedRow.jLabel1NoselectedRowMessage.setText("No Row Selected !!..");
        } else {
            //Clear error message first
            viewSelectedRow.jLabel1NoselectedRowMessage.setText(null);
            System.out.println("selected row value  " + selectedRowForNewJframe);

            //Retrieving jtable selected row
            String newName = model.getValueAt(selectedRowForNewJframe, 0).toString();
            String newGender = model.getValueAt(selectedRowForNewJframe, 1).toString();
            String newProgrammingLanguage = model.getValueAt(selectedRowForNewJframe, 2).toString();
            String newsubject = model.getValueAt(selectedRowForNewJframe, 3).toString();

            JLabel newImageJL = (JLabel) model.getValueAt(selectedRowForNewJframe, 4);
            ImageIcon newImageIcon = (ImageIcon) newImageJL.getIcon();

            //Resize image to fit new Jlabel
            Image newImage = newImageIcon.getImage().getScaledInstance(viewSelectedRow.jLabelImageNewJframe.getWidth(), viewSelectedRow.jLabelImageNewJframe.getHeight(), Image.SCALE_SMOOTH);

            //Displaying selected row on new jframe input fields
            viewSelectedRow.jTextFieldNameNewJframe.setText(newName);
            viewSelectedRow.jTextFieldGenderNewJframe.setText(newGender);
            viewSelectedRow.jTextFieldPLanguageNewJframe.setText(newProgrammingLanguage);
            viewSelectedRow.jTextFieldSubjectNewJframe.setText(newsubject);
            viewSelectedRow.jLabelImageNewJframe.setIcon(new ImageIcon(newImage));

        }
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        clearFields();
    }                                        

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:

        FileOutputStream excelFOU = null;
        BufferedOutputStream excelBOU = null;
        XSSFWorkbook excelJTableExporter = null;

        //Choose Location For Saving Excel File
        JFileChooser excelFileChooser = new JFileChooser("C:\\Users\\Authentic\\Desktop");
//        Change Dilog Box Title
        excelFileChooser.setDialogTitle("Save As");
//        Onliny filter files with these extensions "xls", "xlsx", "xlsm"
        FileNameExtensionFilter fnef = new FileNameExtensionFilter("EXCEL FILES", "xls", "xlsx", "xlsm");
        excelFileChooser.setFileFilter(fnef);
        int excelChooser = excelFileChooser.showSaveDialog(null);

//        Check if save button is clicked
        if (excelChooser == JFileChooser.APPROVE_OPTION) {

            try {
                //Import excel poi libraries to netbeans
                excelJTableExporter = new XSSFWorkbook();
                XSSFSheet excelSheet = excelJTableExporter.createSheet("JTable Sheet");
                //            Loop to get jtable columns and rows
                for (int i = 0; i < model.getRowCount(); i++) {
                    XSSFRow excelRow = excelSheet.createRow(i);
                    for (int j = 0; j < model.getColumnCount(); j++) {
                        XSSFCell excelCell = excelRow.createCell(j);

                        //Now Get ImageNames From JLabel
                        //get the last column
                        if (j == model.getColumnCount() - 1) {
                            JLabel excelJL = (JLabel) model.getValueAt(i, j);
                            ImageIcon excelIMageIcon = (ImageIcon) excelJL.getIcon();
                            //Before retrieving the description of the image first set it...
                            excelImagePath = excelIMageIcon.getDescription();
                        }
                        excelCell.setCellValue(model.getValueAt(i, j).toString());

//                        Change the values of the fourth column to image paths
                        if (excelCell.getColumnIndex() == model.getColumnCount() - 1) {
                            excelCell.setCellValue(excelImagePath);
                        }
                    }
                }   //Append xlsx file extensions to selected files. To create unique file names
                excelFOU = new FileOutputStream(excelFileChooser.getSelectedFile() + ".xlsx");
                excelBOU = new BufferedOutputStream(excelFOU);
                excelJTableExporter.write(excelBOU);
                JOptionPane.showMessageDialog(null, "Exported Successfully !!!........");
            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            } finally {
                try {
                    if (excelBOU != null) {
                        excelBOU.close();
                    }
                    if (excelFOU != null) {
                        excelFOU.close();
                    }
                    if (excelJTableExporter != null) {
                        excelJTableExporter.close();
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }

        }

    }                                        

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:

        File excelFile;
        FileInputStream excelFIS = null;
        BufferedInputStream excelBIS = null;
        XSSFWorkbook excelJTableImport = null;
        //Select Default Path
        String defaultCurrentDirectoryPath = "C:\\Users\\Authentic\\Desktop";
        JFileChooser excelFileChooser = new JFileChooser(defaultCurrentDirectoryPath);
        //Filter Only Excel Files 
        FileNameExtensionFilter fnef = new FileNameExtensionFilter("EXCEL FILES", "xls", "xlsx", "xlsm");
        excelFileChooser.setFileFilter(fnef);
        //Set Dialog Title
        excelFileChooser.setDialogTitle("Select Excel File");
        int excelChooser = excelFileChooser.showOpenDialog(null);
        //If Open Button Is clicked

        if (excelChooser == JFileChooser.APPROVE_OPTION) {
            try {
                excelFile = excelFileChooser.getSelectedFile();
                excelFIS = new FileInputStream(excelFile);
                excelBIS = new BufferedInputStream(excelFIS);
                excelJTableImport = new XSSFWorkbook(excelBIS);
                XSSFSheet excelSheet = excelJTableImport.getSheetAt(0);

                //Looping through excel columns and rows
                for (int row = 0; row < excelSheet.getLastRowNum(); row++) {
                    XSSFRow excelRow = excelSheet.getRow(row);

                    XSSFCell excelNAme = excelRow.getCell(0);
                    XSSFCell excelGender = excelRow.getCell(1);
                    XSSFCell excelProgrammingLanguage = excelRow.getCell(2);
                    XSSFCell excelSubject = excelRow.getCell(3);
                    XSSFCell excelImage = excelRow.getCell(4);

                    //resize images
                    JLabel excelJL = new JLabel(new ImageIcon(new ImageIcon(excelImage.toString()).getImage().getScaledInstance(60, 60, Image.SCALE_SMOOTH)));
                    model.addRow(new Object[]{excelNAme, excelGender, excelProgrammingLanguage, excelSubject, excelJL});

                }

                JOptionPane.showMessageDialog(null, "Imported Successfully.. !! ");
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage());
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage());
            } finally {

                try {
                    if (excelFIS != null) {
                        excelFIS.close();
                    }
                    if (excelBIS != null) {
                        excelBIS.close();
                    }
                    if (excelJTableImport != null) {
                        excelJTableImport.close();
                    }
                } catch (IOException iOException) {
                    JOptionPane.showMessageDialog(null, iOException.getMessage());
                }

            }

        }
    }                                        

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:

        //Delete Selected Row        
        int getSelectedRowForDeletion = jTable1.getSelectedRow();
        //Check if their is a row selected
        if (getSelectedRowForDeletion >= 0) {
            model.removeRow(getSelectedRowForDeletion);
            JOptionPane.showMessageDialog(null, "Row Deleted");
        } else {
            JOptionPane.showMessageDialog(null, "Unable To Delete");
        }
    }                                        

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:

        int[] getSelectedRows = jTable1.getSelectedRows();
        Object[] newFormRows = new Object[4];

        for (int i = 0; i < getSelectedRows.length; i++) {

            newFormRows[0] = model.getValueAt(getSelectedRows[i], 0);
            newFormRows[1] = model.getValueAt(getSelectedRows[i], 1);
            newFormRows[2] = model.getValueAt(getSelectedRows[i], 2);
            newFormRows[3] = model.getValueAt(getSelectedRows[i], 3);

            selectedRowsJFrameForm.SelectedRowsJFrameFormModel.addRow(newFormRows);
        }
        selectedRowsJFrameForm.setVisible(true);
        selectedRowsJFrameForm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }                                        

    private void jButtonPrintActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        try {
            boolean print = jTable1.print();
            if (!print) {
                JOptionPane.showMessageDialog(null, "Unable To Print !!..");
            }
        } catch (PrinterException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }


    }                                            

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AddDataToJTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AddDataToJTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AddDataToJTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AddDataToJTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AddDataToJTable().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JButton jButtonBrowseImage;
    private javax.swing.JButton jButtonPrint;
    private javax.swing.JCheckBox jCheckBoxJava;
    private javax.swing.JCheckBox jCheckBoxPHP;
    private javax.swing.JComboBox jComboBoxSubjects;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelImage;
    private javax.swing.JRadioButton jRadioButtonFemale;
    private javax.swing.JRadioButton jRadioButtonMale;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextFieldName;
    // End of variables declaration                   

    private void clearFields() {
        jTextFieldName.setText("");
        buttonGroup1.clearSelection();
        buttonGroup2.clearSelection();
        jComboBoxSubjects.setSelectedIndex(0);
        jLabelImage.setIcon(null);
    }

}




ViewSelectedRowJFrame.java Source Code




/*
 * Java GUI Swing Tutorial - Netbeans IDE (Project Source Code) - Graphical User Interface (GUI) Complete Beginners Guide (Demo)
 */
package AddDataToJTable;

/**
 *
 * @author Genuine
 */
public class ViewSelectedRowJFrame extends javax.swing.JFrame {

    /**
     * Creates new form ViewSelectedJFrame
     */
    public ViewSelectedRowJFrame() {
        initComponents();
    }

    /**
     * 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() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1NoselectedRowMessage = new javax.swing.JLabel();
        jTextFieldNameNewJframe = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldGenderNewJframe = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldPLanguageNewJframe = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldSubjectNewJframe = new javax.swing.JTextField();
        jLabelImageNewJframe = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(153, 153, 0));

        jLabel1NoselectedRowMessage.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N

        jLabel1.setText("Name");

        jLabel2.setText("Gender");

        jLabel3.setText("P. Language");

        jLabel4.setText("Subject");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addComponent(jLabel1NoselectedRowMessage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldNameNewJframe)
                            .addComponent(jTextFieldGenderNewJframe)
                            .addComponent(jTextFieldPLanguageNewJframe)
                            .addComponent(jTextFieldSubjectNewJframe, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(jLabelImageNewJframe, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldNameNewJframe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextFieldGenderNewJframe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(24, 24, 24)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTextFieldPLanguageNewJframe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTextFieldSubjectNewJframe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabelImageNewJframe, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 96, Short.MAX_VALUE)
                .addComponent(jLabel1NoselectedRowMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ViewSelectedRowJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ViewSelectedRowJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ViewSelectedRowJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ViewSelectedRowJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ViewSelectedRowJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    public javax.swing.JLabel jLabel1NoselectedRowMessage;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    public javax.swing.JLabel jLabelImageNewJframe;
    private javax.swing.JPanel jPanel1;
    public javax.swing.JTextField jTextFieldGenderNewJframe;
    public javax.swing.JTextField jTextFieldNameNewJframe;
    public javax.swing.JTextField jTextFieldPLanguageNewJframe;
    public javax.swing.JTextField jTextFieldSubjectNewJframe;
    // End of variables declaration                   
}



SelectedRowsJFrameForm.java Source Code


/*
 * Java GUI Swing Tutorial - Netbeans IDE (Project Source Code) - Graphical User Interface (GUI) Complete Beginners Guide (Demo)
 */
package AddDataToJTable;

import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Authentic
 */
public class SelectedRowsJFrameForm extends javax.swing.JFrame {

    DefaultTableModel SelectedRowsJFrameFormModel;

    /**
     * Creates new form SelectedRowsJFrameForm
     */
    public SelectedRowsJFrameForm() {
        initComponents();
        tableHeaders();

    }

    //method to display table headers
    public void tableHeaders() {
        SelectedRowsJFrameFormModel = (DefaultTableModel) jTable1.getModel();
        Object[] tableHeaders = new Object[]{"Name", "Gender", "Programming Language", "Subject"};
        SelectedRowsJFrameFormModel.setColumnIdentifiers(tableHeaders);

    }

    /**
     * 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() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(204, 102, 0));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        jButton1.setText("Remove Rows");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(53, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        int rowsToRemove = SelectedRowsJFrameFormModel.getRowCount();
        //remove rows from the bottom one by one
        for (int i = rowsToRemove - 1; i >= 0; i--) {
            SelectedRowsJFrameFormModel.removeRow(i);
        }
    }                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SelectedRowsJFrameForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SelectedRowsJFrameForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SelectedRowsJFrameForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SelectedRowsJFrameForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SelectedRowsJFrameForm().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTable jTable1;
    // End of variables declaration                   
}


Other Graphical User Interface (GUI) Swing Complete Tutorials – Netbeans IDE :

  1. JAVA GUI – How To Make Only One Checkbox Checked At A Time Using Netbeans
    https://www.youtube.com/watch?v=ps518R9za-g
  2. How To Populate Jtable In Java Using Netbeans – Display Data From User Input
    https://www.youtube.com/watch?v=mIeoTjAE14E
  3. How To Reset Jtextfield Jcombobox Jradiobutton Jcheckbox In Java (Netbeans – GUI)
    https://www.youtube.com/watch?v=Az0_2cF-DT8
  4. GUI – Display Selected Row Values From JTable Into JTextfields | radiobuttons | checkbox | Combobox
    https://www.youtube.com/watch?v=9fqG8RBlfXo
  5. Browse For Image File And Display It On Jlabel Using Java Swing
    https://www.youtube.com/watch?v=p4HV2zDcANI
  6. How to Display And Insert Image into JTable Cell From Computer – Java GUI – NetBeans IDE tutorial
    https://www.youtube.com/watch?v=vFItm64F6GU
  7. How To Display Image From JTable Cell To JLabel In Java (Java Source Code)
    https://www.youtube.com/watch?v=x3QMmYQ_7gU
  8. Java – How To Move JTable Selected Rows Up And Down Using NetBeans (GUI)
    https://www.youtube.com/watch?v=PuJolbu9i4o
  9. How To Clear Or Reset Input Field On Button Click Java Jframe Swing Tutorial – Netbeans
    https://www.youtube.com/watch?v=m2_8HARrVHY
  10. How To Open A New Jframe On Button Click In Netbeans
    https://www.youtube.com/watch?v=1VonIsK__V4
  11. How To Set Background Color Of Jframe In Swing In Java – Netbeans (GUI) Tutorial
    https://www.youtube.com/watch?v=y1tv_vdJDJw
  12. How to show JTable Selected Row Data In Another JFrame
    https://www.youtube.com/watch?v=fSQQMlrdmzc
  13. How To Export Jtable Data To Excel In Java Netbeans
    https://www.youtube.com/watch?v=NkDnVFAwfas
  14. How To Import Excel in Java JTable (GUI) Swing Application Tutorial – Netbeans
    https://www.youtube.com/watch?v=sH9XL_Qn_zY
  15. How To Delete Or Remove Selected Row From Jtable In Netbeans – JAVA Tutorial (Source Code)
    https://www.youtube.com/watch?v=YW9LCmjdjNE
  16. JAVA GUI – How To Display JTable Selected Rows On Another JFrame JTabel – Netbeans (Source Code)
    https://www.youtube.com/watch?v=N0m0iCF7wCg
  17. !Source Code!~ How To Clear Java Jtable Rows – Deleting All The Rows In A Jtable (Removing rows)
    https://www.youtube.com/watch?v=2ZtGn7QR3VM
  18. How To Print Jtable Data In Java Swing GUI Application – Netbeans
    https://www.youtube.com/watch?v=IgtY5O9AOzE
  19. How To Add Image Or Icons To Button Java Netbeans
    https://www.youtube.com/watch?v=MwCPV02Yr6M
  20. Step By Step Graphical User Interface (GUI) Beginners Guide – Java GUI Swing Complete Tutorial
    https://www.youtube.com/watch?v=hysfbDX6hMc
  21. Java GUI Swing Tutorial – Netbeans IDE (Project Source Code) – Graphical User Interface (GUI) Complete Beginners Guide (Demo)
    https://www.youtube.com/watch?v=WXlPx8zDOIM

Project Demo

Java GUI Swing Tutorial – Netbeans IDE (Project Source Code) – Graphical User Interface (GUI) Complete Beginners Guide (Demo)

Source Code Download Link

https://github.com/mauricemuteti/Java-Graphical-User-Interface-Swing-Tutorial-Netbeans-IDE-Project-Source-Code

Leave a Reply

Your email address will not be published. Required fields are marked *