편집 가능한 셀의 데이터베이스 관리 테이블에서 레코드가있는 JTable을로드하는 다음 방법이 있습니다.
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);
}
다른 방법에서는 dbQueries.updateAdmin () 메서드를 호출하는 addActionListener가있는 저장 버튼이 있습니다.
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);
}
내 질문은 : 데이터베이스를 업데이트하기 위해 편집 된 모든 셀의 값을 UPDATEADMIN () METHOD에 어떻게 전달합니까? - 감사
모두 감사합니다. 내 대답을 찾았습니다. UPDATEADMIN ()에 전달하기 전에 stopCellEditing ()을해야했습니다. 그래서 여기에 코드가 있습니다 :
if(adminInfoTable.isEditing()){
adminInfoTable.getCellEditor().stopCellEditing();
}
adminInfoTable.getValueAt(
adminInfoTable.getSelectedRow(),
adminInfoTable.getSelectedColumn()
)
그거였다. 그런 다음 셀 편집 값을 전달할 수있었습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다