Wednesday, July 25, 2007

Use TableCellRenderer in swing(java)

follow code example.
public class InfoCheckStockErrorTableCellRenderer extends JCheckBox implements TableCellRenderer{
/** Creates a new instance of InfoCheckStockErrorTableCelRenderer */
public InfoCheckStockErrorTableCellRenderer() {
super();
setHorizontalAlignment(this.CENTER);
}

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
InfoCheckStockErrorTableModel model = (InfoCheckStockErrorTableModel) table.getModel();
setEnabled(!model.getIsAjustFromDB(row));
if (isSelected) {
setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground());
} else {
setForeground(table.getForeground());
setBackground(table.getBackground());
}
boolean isAjust = ((Boolean) value).booleanValue();
setSelected(isAjust);
return this;
}
}

JAVA singleton class

Code below, you can make singlton class(has only one object).
public class AppFunction {
private static AppFunction af;
private AppFunction() {
}
public static AppFunction getInstance(){
if(af!=null){
return af;
} else{
af = new AppFunction();
return af;
}
}
}

Tuesday, July 24, 2007

JAVA Printing vs Font size

You can get the height of line from font. Example according code below.
public int print(Graphics g, PageFormat pf, int pageIndex){
Font font = new Font("Serif", Font.PLAIN, 14);
FontMetrics metrics = g.getFontMetrics(font);
int lineHeight = metrics.getHeight();
}

Dotmetric Printer vs java Programing

The paper must have height more than width.
The printer can set the position of paper in and paper out(for cutting paper) in continue paper.

Thai language with MySQL

db.connection("jdbc:mysql://"+dbIp+"/"+dbName+"?user=root&password=1234&useUnicode=true&characterEncoding=UTF-8");
Because of in java code (Netbeans) use UTF-8 Encoding, so I need to connect with UTF-8 encoding.
After this point I always will write or read Thai language from DB.