// Fees update method private void updateFeesData(long id) { String columns[] = {"Course", "Fees Payed", "Total fees", "Installments"}; try { Database db = new Database(); panel_7.removeAll(); feestablemodel = new MyTableModel(db.getFeeData(id), columns); feestable = new JTable(feestablemodel); feestable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); feestable.getSelectionModel().addListSelectionListener(this); feesscrollpane = new JScrollPane(feestable); panel_7.add(feesscrollpane); // change fees payed label feespayedlabel.setText("Fees Payed"); feesduelabel.setText("Fees Due"); totalfeeslabel.setText("Total Fees"); panel_7.revalidate(); } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage(), null, JOptionPane.ERROR_MESSAGE); } }
// Implementation of valueChanged public void valueChanged(ListSelectionEvent e) { if (e.getSource() == table.getSelectionModel()) { ListSelectionModel ls = table.getSelectionModel(); int index = ls.getMinSelectionIndex(); long id = (long) table.getValueAt(index, 0); updateFeesData(id); } else { ListSelectionModel ls = feestable.getSelectionModel(); int index = ls.getMinSelectionIndex(); float feespayed = (float) feestable.getValueAt(index, 1); float totalfees = (float) feestable.getValueAt(index, 2); feespayedlabel.setText("Fees Payed: " + feespayed); totalfeeslabel.setText("Total Fees: " + totalfees); if (totalfees - feespayed > 0) { feesduelabel.setText("Fees Due: " + (totalfees - feespayed)); } panel_6.revalidate(); } }