Home > Uncategorized > Alignment & Number Renderer

Alignment & Number Renderer

Untuk mengatur horizontal alingment dan number format pada jTable, dengan mudah menggunakan setCellRenderer().

Berikut sebagai contoh:

DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
NumberFormat formatter = new DecimalFormat("#,###");

private void inisiasiTable(String strFilter) {
jTable_Produk.setModel(connectionsqlitedb.getTableModel(
"SELECT "
+ "id_produk AS 'ID', "
+ "nama_produk AS 'NAMA', "
+ "harga_satuan AS 'HARGA SATUAN', "
+ "harga_pack AS 'HARGA PACK' "
+ "FROM tbl_produk"
));

centerRenderer.setHorizontalAlignment( DefaultTableCellRenderer.CENTER );
jTable_Produk.getColumnModel().getColumn(0).setCellRenderer( centerRenderer );
jTable_Produk.getColumnModel().getColumn(2).setCellRenderer( NumberRenderer.getDecimalRenderer() ); jTable_Produk.getColumnModel().getColumn(3).setCellRenderer( NumberRenderer.getDecimalRenderer() );

}

Screenshot from 2016-09-01 19-17-30

contoh diatas, column(0) dengan align Center, dan column(2) dan (3) dengan format angka dengan thousand separator.

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: