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

[6308 byte] By [William.Anthonya] at [2007-11-27 5:51:09]
# 1

> **The code might not run on your computer, since I have my own package imported into it.

Of course the code won't run. It is nowhere near a complete program. There is no main method. There is no GUI. So I don't now why you bothered adding that comment.

> I have tried using other thread for database process

Well, you are not using a Thread. Creating a Runnable object does not make a Thread. You need to create a Thread using a Runnable object.

I'm not sure what you real problem is. I don't see why you need to use an AncestorListener. Your basic code should be something like:

a) create all the components and add them to the frame

b) make the frame visible. Once the frame is visible it can start responding to events

c) start your Thread for database access

No need to worry about synchronized methods if you follow the guidelines in this article:

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html

camickra at 2007-7-12 15:39:45 > top of Java-index,Desktop,Core GUI APIs...
# 2

> Of course the code won't run. It is nowhere near a

> complete program. There is no main method. There is

> no GUI. So I don't now why you bothered adding that

> comment.

>

Sorry, It's only my module, I forgot to include the main application.

> Well, you are not using a Thread. Creating a Runnable

> object does not make a Thread. You need to create a

> Thread using a Runnable object.

>

What the difference of those?

> No need to worry about synchronized methods if you

> follow the guidelines in this article:

>

> http://java.sun.com/products/jfc/tsc/articles/threads/

> threads1.html

It's singleton actually

William.Anthonya at 2007-7-12 15:39:45 > top of Java-index,Desktop,Core GUI APIs...
# 3
Ok, I got your point. Thanks alot.
William.Anthonya at 2007-7-12 15:39:45 > top of Java-index,Desktop,Core GUI APIs...