I have a Java Class, i create a Query (JPA with EclipseLink) to Load Info from DB when a JTabbedPane is clicked, the data is loaded into the TableModel which is bound to a JTable. I use MouseClicked of MouseEvent, to get the selected tab. But some tables fail to load, i feel as if nothing is clicked, but when i go around through the tabs and come back to the tab that failed to load it eventually loads the data sometimes. My Code below:
private void jTabbedPane1MouseClicked(java.awt.event.MouseEvent evt) {
int selectTab = jTabbedPane1.getSelectedIndex();
if (selectTab == 1) {
bookValueTable.getColumnModel().getColumn(0).setMaxWidth(150);
bookValueTable.getColumnModel().getColumn(1).setMaxWidth(150);
if (!tab2Opened) { //this makes sure the data is not loaded multiple time....
tab2Opened = true;
Query q = em.createQuery("select e from EnterpriseInvestments e Where e.acctYear = :acctYear");
q.setParameter("acctYear", acctYear);
List<EnterpriseInvestments> resultList = q.getResultList();
for(EnterpriseInvestments p: resultList){
Object row[] = {p.getEnterprise().getRcNo(), p.getAcctYear(), p.getInvestmentItem(),
nf.format(p.getInvestmentAmount())};
shareCapitalModel.addRow(row);
}
}
bookValueTable.setRowSorter(new TableRowSorter(shareCapitalModel));
}
I dont know where the problem is coming from: The JPA, The TabbedPane or the EventHandler!