Wednesday, July 7, 2010

Customized TableModel

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

public class CustomizedTableModel extends AbstractTableModel
{
private String[] columnNames;
Vector cache;
String[] headers;
int colCount;
int dataLength;
private Object[][] data;
Class type[] = null;
public CustomizedTableModel(Class [] coltype, String [] columnNames)
{
type = coltype;
this.columnNames = columnNames;
headers = columnNames;
colCount = coltype.length;
cache = new Vector();

}

public int getColumnCount() {

return colCount;
}

public int getRowCount() {
return dataLength;

}


public String getColumnName(int col) {

return headers[col];
}

public Object getValueAt(int row, int col) {
return data[row][col];

}


public Class getColumnClass(int col) { return type[col]; }



public boolean isCellEditable(int row, int col) {
return false;
}


public void setValueAt(Object value, int row, int col) {

data[row][col] = value;
fireTableCellUpdated(row, col);

}

public void setDataSet(String[][] data)
{
dataLength = data.length;
try {
this.data = new Object[data.length][colCount];
for (int i = 0; i < data.length; i++)
{
for(int j = 0; j < colCount; j++)
{
this.data[i][j] = data[i][j];
}
}
}
catch(Exception e)
{
cache = new Vector();
e.printStackTrace();
}
fireTableChanged(null);

}
}



///calling of it///////////////

Class coltype [] = {String.class,String.class,String.class};
String colNames [] = {"EmpId","First Name","Last Name"};
CustomizedTableModel ctm = new CustomizedTableModel(coltype,colNames);

Tuesday, July 6, 2010

make a unsigned jar to a signed jar

http://wiki.plexinfo.net/index.php?title=How_to_sign_JAR_files


Signing with a Test Certificate

1. Make sure that you have a Java SDK keytool and jarsigner in your path. These tools are located in the Java SDK bin directory.

2. Create a new key in a new keystore as follows:

keytool -genkey -keystore myKeystore -alias myself

You will be prompted for information regarding the new key, such as password, name, etc. This will create the myKeystore file on disk.

3. Then create a self-signed test certificate as follows:

keytool -selfcert -alias myself -keystore myKeystore

This will prompt you for a password. Generating the certificate may take a few minutes.

4. Check to make sure that everything is okay. To list the contents of the keystore, use this command:

keytool -list -keystore myKeystore

It should list something like:

Keystore type: jks
Keystore provider: SUN


Your keystore contains 1 entry:
myself, Tue Jan 23 19:29:32 PST 2001, keyEntry,
Certificate fingerprint (MD5):
C2:E9:BF:F9:D3:DF:4C:8F:3C:5F:22:9E:AF:0B:42:9D

5. Finally, sign the JAR file with the test certificate as follows:

jarsigner -keystore myKeystore test.jar myself

6. Repeat these steps for all your JAR files.

Note that a self-signed test certificate should only be used for internal testing, since it does not guarantee the identity of the user and therefore cannot be trusted. A trustworthy certificate can be obtained from a certificate authority, such as VeriSign orThawte, and should be used when the application is put into production

Make sure you add the following tag to your .jnlp file: