private void myProfileTabStateChanged(javax.swing.event.ChangeEvent evt) {
if (myProfileTab.getSelectedComponent() == EditProfile) {
editProfile();
} else if (SearchAcademic == myProfileTab.getSelectedComponent()) {
AcademicDAO aDao = new AcademicDAO();
try {
List<AcademicDTO> listAll = aDao.listAll(AcademicDTO.class);
searchTable.setData(listAll);
} catch (DBException ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public class ListDataUI<T extends BaseDTO> extends javax.swing.JPanel {
public ListDataUI() {
this.summaryColumnsAndTheirViewNames = Collections.emptyMap();
this.dtoSummaryFields = Collections.emptyList();
this.summaryTableModel = new SummaryTableModel();
initComponents();
this.summaryTable.setModel(summaryTableModel);
initListeners();
}
/**
* Creates new form ListDataUI
*/
public ListDataUI(LinkedHashMap<String, String> summaryColumnsAndTheirViewNames) {
this.summaryColumnsAndTheirViewNames = summaryColumnsAndTheirViewNames;
this.dtoSummaryFields = new ArrayList<String>(summaryColumnsAndTheirViewNames.keySet());
this.summaryTableModel = new SummaryTableModel();
initComponents();
this.summaryTable.setModel(summaryTableModel);
initListeners();
}
public ListDataUI(List<String> dtoSummaryFields) {
this.summaryColumnsAndTheirViewNames = Collections.emptyMap();
this.dtoSummaryFields = new ArrayList<String>(dtoSummaryFields);
this.summaryTableModel = new SummaryTableModel();
initComponents();
this.summaryTable.setModel(summaryTableModel);
initListeners();
}
/**
* 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() {
tableSp = new javax.swing.JScrollPane();
summaryTable = new javax.swing.JTable();
setLayout(new java.awt.BorderLayout());
summaryTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
tableSp.setViewportView(summaryTable);
add(tableSp, java.awt.BorderLayout.CENTER);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JTable summaryTable;
private javax.swing.JScrollPane tableSp;
// End of variables declaration
private List<T> data;
private Map<String, String> summaryColumnsAndTheirViewNames;
private List<String> dtoSummaryFields;
private SummaryTableModel summaryTableModel;
public List<T> getData() {
return data;
}
public void removeSelectedDataRow() {
final int selectedRow = summaryTable.getSelectedRow();
if (selectedRow != -1) {
final int modelIndex = summaryTable.convertRowIndexToModel(selectedRow);
data.remove(modelIndex);
summaryTableModel.fireTableRowsDeleted(modelIndex, modelIndex);
}
}
public void setData(List<T> data) {
this.data = data;
summaryTableModel.fireTableDataChanged();
if (data.size() > 0) {
summaryTable.getSelectionModel().setSelectionInterval(0, 0);
}
}
我试图在表中显示来自数据库的行数据searchTable
,我调用该setData()
方法。我在“searchTable.setData(listAll);”行设置了一个断点,listAll 包含数据库中的所有数据,但没有显示在 searchTable 上。