Wednesday, January 9, 2008

I know you can fight...

"I can fight", said young William. "I know you can fight. But its the WITS that make us man.", replied the father.

Tuesday, November 13, 2007

Heap size: java.lang.OutOfMemoryError

To avoid java.lang.OutOfMemoryError when dealing with swing programming or IO files with large size, just tune the heap size or your java virtual machine:

Syntax:
java -Xms_initial heap size_ -Xmx_max heap size_
Default:
java -Xms32m -Xmx128m
In my case, I increased it to 512MB such as
java -Xms32m -Xmx512m

Resources:
[1] http://edocs.bea.com/wls/docs61/perform/JVMTuning.html
[2] http://hausheer.osola.com/docs/5

Thursday, October 11, 2007

Good usage of anonymous inner class

I just found out a good usage of anonymous inner class. Code shown below is an alternative of creating an AbstractTableModel that sets the table editable mode to off.
JTable table = new JTable(){
public boolean isEditable(){
return true;
}
}
The result is clean code plus I can set the table's model to DefaultTableModel with uneditable table cell mode.

Tuesday, October 9, 2007

Problem on ImageIcon when path is a URL

I am still figuring out how to add remote icon for a swing component given the URL path of the image. The constructor new ImageIcon(URL) is not working.

Monday, October 8, 2007

Javascript sample

This blog post exhibits jquery usage to toggle appearance of a phrase.

Click here
Allan here doing js.


Monday, October 1, 2007

Proper execution of Java Swing

Swing event-handling and painting code executes in a single thread, called the event-dispatching thread. This ensures that each event handler finishes executing before the next one executes and that painting isn't interrupted by events. To avoid the possibility of deadlock, you must take extreme care that Swing components and models are created, modified, and queried only from the event-dispatching thread.

Using SwingUtilities.invokeLater to ensure that the code executes on a special thread.
Threads - lightweight processes that can run concurrently.

The invokeLater method returns immediately, without waiting for the event-dispatching thread to execute the code. This inhibits the deadlock that maybe caused by updating and repainting of GUI component.

Example:
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MyJFrame f = new MyJFrame();
// set center location
f.setLocationRelativeTo(null);
// show GUI
f.setVisible(true);
}
});

Hacking Blogspot