I have following method, which is loading a JTable with records from Database Admin table in the Editable cells.
private void renderAdminInfoTable() {
adminInfoTable = new JTable();
adminInfoTable.setPreferredScrollableViewportSize(new Dimension(400, 181));
adminInfoTable.setFillsViewportHeight(true);
adminInfoTable.setBackground(ARSColour.TRANSPARENTBLUE);
adminInfoTable.setGridColor(new Color(128, 128, 128, 50));
adminInfoTable.setRowHeight(32);
adminInfoTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
adminInfoTable.setShowVerticalLines(false);
DefaultTableModel model = new DefaultTableModel() {
@Override
public boolean isCellEditable(int row, int column) {
switch (row){
case 0://Name
return false;
case 1: //Email
if(column == 1)
return true;
else
return false;
case 2: //Phone
if(column == 1)
return true;
else
return false;
default:
return false;
}
}
};
adminInfoTable.setModel(model);
//Create the scroll pane and add the table to it.
scrollPaneInfo = new JScrollPane(adminInfoTable);
this.add(scrollPaneInfo);
scrollPaneInfo.setBounds(36+20, 768 - 628+10, 400-20*2, 181-10);
scrollPaneInfo.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
scrollPaneInfo.setBackground(ARSColour.TRANSPARENTBLUE);
JScrollBar sb = scrollPaneInfo.getVerticalScrollBar();
sb.setUI(new MyScrollbarUI());
// sets width of scrollbar
Dimension scrollBarDim = new Dimension(10, sb
.getPreferredSize().height);
sb.setPreferredSize(scrollBarDim);
}
In another method I've a Save button with addActionListener with will call dbQueries.updateAdmin() method.
public void renderAdminInformationPanel() {
AdminInfoLabel = new JLabel("Edit Admin Information");
AdminInfoLabel.setFont(new Font("Open Sans", Font.PLAIN, 22));
AdminInfoLabel.setBounds(36, 768 - 662 - 6, AdminInfoLabel.getPreferredSize().width, AdminInfoLabel.getPreferredSize().height);
AdminInfoLabel.setForeground(ARSColour.BRIGHTBLUE);
AdminInfoLabel.setBackground(ARSColour.WHITE);
AdminInfoLabel.setOpaque(true);
this.add(AdminInfoLabel);
btnSave = new JButton("Save");
btnSave.setBounds(196, 998 - 662 - 6, btnSave.getPreferredSize().width, btnSave.getPreferredSize().height);
btnSave.setOpaque(true);
this.add(btnSave);
btnSave.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
dbQueries.updateAdmin(); //HERE IS THE METHOD CALL WHERE I NEEDED TO PASS ALL EDITED COLUMNS IN ORDER TO SAVE INTO DATABASE.
}
});
renderAdminInfoTable();
tableBackground = new JPanel();
this.add(tableBackground);
tableBackground.setBounds(36, 768 - 628, 400, 181);
tableBackground.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
tableBackground.setBackground(ARSColour.TRANSPARENTBLUE);
adminInfoPanel = backgroundJPanel(24, 768-675, 424, 340);
}
My question is: How would I pass all edited cell's value IN UPDATEADMIN() METHOD in order to update the Database? - Thanks