Detect whether the component is completely loaded and displayed
I need to know how to detect whether the component is completely loaded and displayed for my database application, because my application seems to wait for displaying until database process is completed.
Below is what I've done, I have tried using other thread for database process and using ancestorlistener, but the UI still waiting for the database loading.
**The code might not run on your computer, since I have my own package imported into it.
package bin;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import wLib.xBase.*;
import wLib.util.*;
publicclass customer_0extends JPanelimplements ActionListener, AncestorListener{
privatestatic customer_0 instance;
private wTable tblBrowse;
private JButton btnlinkPrd;
private JButton btnKategori;
private JButton btnExit;
publicstaticsynchronized customer_0 getInstance(){
if (instance==null)
instance =new customer_0();
return instance;
}
private customer_0(){
super();
showUI();
}
privatevoid showUI(){
setName("Customer");
setLayout(new BorderLayout());
tblBrowse =new wTable();
JPanel pnlBtm =new JPanel();
btnlinkPrd =new JButton("Link Produk");
btnlinkPrd.setMnemonic((int)'l');
btnKategori =new JButton("Set Category");
btnKategori.setMnemonic((int)'s');
btnExit =new JButton("Exit");
btnExit.setMnemonic((int)'x');
pnlBtm.add(btnlinkPrd);
pnlBtm.add(btnKategori);
pnlBtm.add(btnExit);
add(new JScrollPane(tblBrowse), BorderLayout.CENTER);
add(pnlBtm, BorderLayout.PAGE_END);
btnlinkPrd.addActionListener(this);
btnKategori.addActionListener(this);
btnExit.addActionListener(this);
this.addAncestorListener(this);
}
privatevoid loadData(){
new Runnable(){
publicvoid run(){
try{
xDataSet dataSet=new xDataSet(wToolkit.loadSQLFile("sql\\p_customer_browse"));
dataSet.execute();
tblBrowse.boundData(dataSet);
dataSet.dispose();
}catch (Exception E){
errHandler.dispatchException(Thread.currentThread(), E);
}finally{
tblBrowse.requestFocusInWindow();
}
}
}.run();
}
publicvoid actionPerformed(ActionEvent e){
if (e.getSource()==btnlinkPrd){
}elseif (e.getSource()==btnKategori){
}elseif (e.getSource()==btnExit){
instance =null;
main.getInstance().closeFrame(this);
}
}
publicvoid ancestorMoved(AncestorEvent event){}
publicvoid ancestorRemoved(AncestorEvent event){}
publicvoid ancestorAdded(AncestorEvent event){
loadData();
}
}
What I intend to do is load and display all component first, after that, load the database while displaying progress bar or some indicator.
Message was edited by:
William.Anthony

