How to set and reset color of selected row in jtable

Hi i have a Table when i modify value of selected row then i want to set color for the selected row how can i do it plz help me
[134 byte] By [socmaga] at [2007-11-27 9:39:24]
# 1

> Hi i have a Table when i modify value of selected row

> then i want to set color for the selected row how

> can i do it plz help me

Add a TableModelListener to the TableModel and put the Color to a Map.

Example:

model.addTableModelListener(new TableModelListener() {

public void tableChanged(final TableModelEvent e) {

int selectedRow = table.getSelectedRow();

colorMap.put(String.valueOf(selectedRow), "red");

table.updateUI();

}

});

Override the method "prepareRenderer" of JTable.

There you can get the Color from the Map and set the background accordingly.

Example:

table = new JTable( model ) {

public Component prepareRenderer(

final TableCellRenderer renderer, final int row, final int column) {

Component c = super.prepareRenderer(renderer, row, column);

String key = String.valueOf(row);

c.setBackground(Color.white );

boolean selected = isRowSelected(row) && isColumnSelected(column);

if( selected ){

c.setBackground(Color.cyan);

}

String colorValue = colorMap.get(key);

if( colorValue!=null ){

if( (colorValue).equals("red") ){

c.setBackground(Color.red);

if( selected ){

c.setBackground(redSelected);

}

}

if( (colorValue).equals("white") ) {

c.setBackground(Color.white);

if( selected ){

c.setBackground(Color.cyan);

}

}

}

return c;

}

};

To reset all colors, you simply clear the colorMap and call table.updateUI().

To reset only one row, you put "white" to that row in the colorMap and call table.updateUI().

Andre_Uhresa at 2007-7-12 23:14:42 > top of Java-index,Desktop,Core GUI APIs...
# 2
can u tell me how to use preparerenderer method becoz i already create jtablecan i use preparerenderer method with using JTable construtorplz help me
socmaga at 2007-7-12 23:14:42 > top of Java-index,Desktop,Core GUI APIs...
# 3
Would you please show your code that creates the JTable?
Andre_Uhresa at 2007-7-12 23:14:42 > top of Java-index,Desktop,Core GUI APIs...
# 4

i use this class to set model for my table and i want when user modify value in jtable then color of selected row set red based on modify value

class TableModel extends AbstractTableModel{

/**

* The <code>Vector</code> of <code>Vectors</code> of <code>Object</code> values.

*/

private Vector dataVector;

/**

* Number of the columns visible in the table. -1 means all the columsn are visible.

*/

private int visibleColumnCount = -1;

/**

* This array contains the column headers.

*/

private String columns[] = new String[] {};

/**

* Returns false regardless of parameter values resulting in a non editable table.

*

*/

public boolean isCellEditable(int nRow, int nCol) {

if(nCol==2)

return true;

else

return false;

}

/**

* Specifies the classes associated with the table model .

*/

// String[] columnNames = { "Date", "Invoice No", "Due Date", "Amount", "Paymnet", "Net Balance" };

Class columnClasses[] = { Date.class, String.class, String.class,BigDecimal.class,BigDecimal.class,BigDecimal.class,String.class,Integer.class,Integer.class};

/**

* Returns the <code>Object</code> that contains the table's data values. The object represents a single row

* of values.

*

*/

public Object getRow(int rowNum) {

if (dataVector == null || rowNum > dataVector.size())

return null;

else

return dataVector.elementAt(rowNum);

}

/**

* Adds a row to the end of the model. The new row will contain <code>null</code> values unless

* <code>rowData</code> is specified. Notification of the row being added will be generated.

*

* @param row optional data of the row being added

*/

public void addRow(Object row) {

if (dataVector == null) {

dataVector = new Vector();

}

dataVector.add(row);

// fire the event to the ui informing it that the row has been added

// to the model.

fireTableRowsInserted(dataVector.size(), dataVector.size());

}

public void clear() {

try{

dataVector.clear();

}catch(Exception e)

{

}

fireTableChanged(null);

}

public void TableChanged() {

// dataVector.clear();

fireTableChanged(null);

}

public void deleteRow(int rowNum) {

dataVector.remove(rowNum);

// fire the event to the ui informing it that the row has been

// deleted from the model.

fireTableRowsDeleted(dataVector.size(), dataVector.size());

}

/**

* Returns an attribute value for the cell at <code>row</code> and <code>column</code>. This is an

* important method as it will return the mapping of the column number with its values. also the value should be

* returned properly so that the table could render it.

*

* @param row the row whose value is to be queried

* @param column the column whose value is to be queried

* @return the value Object at the specified cell

* @exception ArrayIndexOutOfBoundsException if an invalid row or column was given

*/

public Object getValueAt(int nRow, int nCol) {

if (nRow < 0 || nRow >= getRowCount())

return "";

FourColumn row = (FourColumn) dataVector.elementAt(nRow);

switch (nCol) {

case 0:

return row.GetDate();

case 1:

return row.getAccountName();

case 2:

return row.getChequeNo();

case 3:

return row.getDebit();

case 4:

return row.getCredit();

case 5:

return row.getTotal();

case 6:

return row.getChequeCleared();

case 7:

return row.GetLedId();

case 8:

return row.getTranId();

}

return "";

}

/**

* Returns the number of rows in this data table.

*

* @return the number of rows in the model

*/

public int getRowCount() {

return dataVector == null ? 0 : dataVector.size();

}

/**

* Returns the number of columns to be visible in this data table. If the visible count is not set then default

* to all the columns

*

* @return the number of visible columns in the model

*/

public int getColumnCount() {

if (visibleColumnCount > -1)

return visibleColumnCount;

else

return columns.length;

}

/**

* Returns the column name.

*

* @return a name for this column using the string value of the appropriate member in

* <code>columnIdentifiers</code>. If <code>columnIdentifiers</code> does not have an entry for

* this index, returns the default name provided by the superclass

*/

public String getColumnName(int col) {

if (col < columns.length) {

return columns[col];

} else {

return null;

}

}

public Class getColumnClass(int c) {

return columnClasses[c];

}

/**

* Sets the visible number of Columns in this table model.

*

* @param visibleColumnCount

*/

public void setVisibleColumnCount(int visibleColumnCount) {

this.visibleColumnCount = visibleColumnCount;

}

/**

* Get the Column headers.

*

* @return

*/

public String[] getColumns() {

return columns;

}

/**

* Sets the column headers.

*

* @param columns

*/

public void setColumns(String[] columns) {

this.columns = columns;

}

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

bookVector getVal=(bookVector)dataVector.elementAt(row);

getVal.setInitialInvoiceNo(Integer.parseInt(value.toString()));

fireTableCellUpdated(row, col);

}*/

}

socmaga at 2007-7-12 23:14:42 > top of Java-index,Desktop,Core GUI APIs...
# 5
Sorry, your code shows the TableModel. That's not what I asked!
Andre_Uhresa at 2007-7-12 23:14:43 > top of Java-index,Desktop,Core GUI APIs...
# 6

plz Check this code when i click on btnChequeCleared button i set "Y" in selected row's cell and then i want to set red color for selected row

plz help me

package com.as.client.asui;

import java.awt.Color;

import java.awt.Component;

import java.awt.Font;

import java.awt.event.ActionListener;

import java.awt.event.InputEvent;

import java.awt.event.ItemEvent;

import java.awt.event.KeyEvent;

import java.math.BigDecimal;

import java.sql.Date;

import java.util.ArrayList;

import java.util.Vector;

import javax.swing.DefaultCellEditor;

import javax.swing.JComponent;

import javax.swing.JOptionPane;

import javax.swing.JTable;

import javax.swing.KeyStroke;

import javax.swing.ListSelectionModel;

import javax.swing.event.ChangeEvent;

import javax.swing.event.TableModelEvent;

import javax.swing.event.TableModelListener;

import javax.swing.table.AbstractTableModel;

import javax.swing.table.DefaultTableCellRenderer;

import javax.swing.table.DefaultTableColumnModel;

import javax.swing.table.TableCellEditor;

import javax.swing.table.TableCellRenderer;

import javax.swing.table.TableColumn;

import javax.swing.table.TableColumnModel;

import org.openide.windows.TopComponent;

import com.as.client.asui.common.AutoFillTextField;

import com.as.client.asui.common.CompletionUI;

import com.as.client.asui.common.DateControl;

import com.as.common.Constants;

import com.as.common.FourColumn;

import com.as.common.LedgerDetail;

import com.as.common.VouDetail;

import com.as.common.bookVector;

import com.as.common.func;

import com.as.common.narrations;

import com.as.common.messages.CompDetail;

import com.as.common.messages.CreateVoucher;

import com.as.common.messages.GenericResponse;

/**

* This class handle bank reconcilation statement

*/

public class BankReconPanel extends javax.swing.JPanel {

private TopComponent parent;

private ASController controller;

private TableModel model=new TableModel();

private Vector tabledetail;

private int BankID;

private BigDecimal opb;

private Vector CompInfo;

private int noOfDecPlaces;

private noOfDecPlaces decplaces;

private int transactionId;

private String debitCredit;

private boolean submitButton;

private boolean submitStatementButton;

private int Id;

private String bankCash;

private String DebtorCreditor;

private Date FinancYrTo;

private Date BooksBeg;

private Vector tempVoucInfo;

private int selectedRow;

private java.util.Date tempVoucDate;

private DefaultTableColumnModel Acm;

//private Integer BankID;

/** Creates new form BankReconPanel */

public BankReconPanel(ASController controller, TopComponent component) {

this.parent=component;

this.controller=controller;

decplaces=new noOfDecPlaces();

CompData();

txtDate = new DateControl(controller.getParent());

txtNarration = new AutoFillTextField(getNarrationData());

legerAcctCompletionUI=new CompletionUI(controller.getParent(), getLedgerData());

initComponents();

addKeyListener();

txtAmount.setText("0.0");

String[] columnNames = { "Date", "Accounts Heading","Cheque No","Debit(Amount)","Credit(Amount)","Balance","Cheque Clearence","LedgerID","TransactionID" };

model.setColumns(columnNames);

model.setVisibleColumnCount(6);

DisplayTable.setModel(model);

}

public void handleLedgerCreated() {

legerAcctCompletionUI.setDataList(getLedgerData());

}

public void handleLedgerUpdated()

{

legerAcctCompletionUI.setDataList(getLedgerData());

}

public void handleLedgerDelete() {

legerAcctCompletionUI.setDataList(getLedgerData());

}

public void CloseUI()

{

try

{

legerAcctCompletionUI.closeUI();

}catch(Exception e){}

}

public ArrayList getLedgerData() {

ArrayList<String> ledgerInfo = new ArrayList<String>();

Vector allLedgerInfo = controller.getAllLedgerDetails();

if (allLedgerInfo != null) {

for (int i = 0; i < allLedgerInfo.size(); i++) {

LedgerDetail element = (LedgerDetail) allLedgerInfo.elementAt(i);

if ((func.isGroupType(element.getGroupId(), this.controller.getlgroupInfo(), Constants.BankGroup,

ASController.getDefault().getAllLedgerGroupDetailsByRefid()) == false)

&& (func.isGroupType(element.getGroupId(), this.controller.getlgroupInfo(),

Constants.CashGroup, ASController.getDefault().getAllLedgerGroupDetailsByRefid()) == false)

&& (func.isGroupType(element.getGroupId(), this.controller.getlgroupInfo(),

Constants.WorkingCapitalLoanGroup, ASController.getDefault().getAllLedgerGroupDetailsByRefid()) == false)) {

ledgerInfo.add(element.getName());

}

}

}

return ledgerInfo;

}

public Vector getNarrationData() {

Vector narrInfo = new Vector();

Vector<String> retNarrInfo = new Vector<String>();

narrInfo = ASController.getDefault().getNarrationInfo();

if (narrInfo != null)

{

for (int i = 0; i < narrInfo.size(); i++) {

narrations element=(narrations)narrInfo.elementAt(i);

retNarrInfo.add(element.getNarration().toString());

}

}

return retNarrInfo;

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents

private void initComponents() {

jPanel1 = new javax.swing.JPanel();

jScrollPane1 = new javax.swing.JScrollPane();

DisplayTable = new javax.swing.JTable();

jPanel2 = new javax.swing.JPanel();

jLabel1 = new javax.swing.JLabel();

//txtDate = new javax.swing.JTextField();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

txtAmount = new javax.swing.JTextField();

jcombDC = new javax.swing.JComboBox();

jLabel5 = new javax.swing.JLabel();

//txtNarration = new javax.swing.JTextField();

btnSubmit = new javax.swing.JButton();

btnCancel = new javax.swing.JButton();

//legerAcctCompletionUI = new javax.swing.JTextField();

btnClearCheque = new javax.swing.JButton();

jLabel6 = new javax.swing.JLabel();

txtBankBalBook = new javax.swing.JTextField();

jLabel7 = new javax.swing.JLabel();

txtBankBalRecords = new javax.swing.JTextField();

jLabel8 = new javax.swing.JLabel();

txtUnreConAmt = new javax.swing.JTextField();

btnSubmitStatment = new javax.swing.JButton();

jLabel4 = new javax.swing.JLabel();

txtChequeNotClered = new javax.swing.JTextField();

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Bank Reconcilation Statement", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14)));

DisplayTable.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

{null, null, null, null},

{null, null, null, null},

{null, null, null, null},

{null, null, null, null}

},

new String [] {

"Title 1", "Title 2", "Title 3", "Title 4"

}

));

DisplayTable.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

DisplayTableMouseClicked(evt);

}

});

jScrollPane1.setViewportView(DisplayTable);

jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Bank Voucher", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12)));

jLabel1.setText("Date");

jLabel2.setText("Account Heading");

jLabel3.setText("Amount");

txtAmount.setNextFocusableComponent(jcombDC);

txtAmount.addFocusListener(new java.awt.event.FocusAdapter() {

public void focusGained(java.awt.event.FocusEvent evt) {

txtAmountFocusGained(evt);

}

public void focusLost(java.awt.event.FocusEvent evt) {

txtAmountFocusLost(evt);

}

});

jcombDC.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Dr", "Cr" }));

jcombDC.setNextFocusableComponent(txtNarration);

jcombDC.addItemListener(new java.awt.event.ItemListener() {

public void itemStateChanged(java.awt.event.ItemEvent evt) {

jcombDCItemStateChanged(evt);

}

});

jcombDC.addFocusListener(new java.awt.event.FocusAdapter() {

public void focusGained(java.awt.event.FocusEvent evt) {

jcombDCFocusGained(evt);

}

});

jLabel5.setText("Narration");

txtNarration.setNextFocusableComponent(btnSubmit);

txtNarration.addFocusListener(new java.awt.event.FocusAdapter() {

public void focusGained(java.awt.event.FocusEvent evt) {

txtNarrationFocusGained(evt);

}

});

btnSubmit.setText("Submit");

btnSubmit.setNextFocusableComponent(btnCancel);

btnSubmit.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnSubmitActionPerformed(evt);

}

});

btnCancel.setText("Cancel");

btnCancel.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnCancelActionPerformed(evt);

}

});

legerAcctCompletionUI.setNextFocusableComponent(txtAmount);

legerAcctCompletionUI.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

legerAcctCompletionUIActionPerformed(evt);

}

});

legerAcctCompletionUI.addFocusListener(new java.awt.event.FocusAdapter() {

public void focusGained(java.awt.event.FocusEvent evt) {

legerAcctCompletionUIFocusGained(evt);

}

public void focusLost(java.awt.event.FocusEvent evt) {

legerAcctCompletionUIFocusLost(evt);

}

});

org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);

jPanel2.setLayout(jPanel2Layout);

jPanel2Layout.setHorizontalGroup(

jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jPanel2Layout.createSequentialGroup()

.addContainerGap()

.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)

.add(jPanel2Layout.createSequentialGroup()

.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jLabel1)

.add(jLabel2)

.add(jLabel3))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)

.add(legerAcctCompletionUI)

.add(jPanel2Layout.createSequentialGroup()

.add(txtAmount, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 79, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(jcombDC, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(txtDate))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 4, Short.MAX_VALUE))

.add(jPanel2Layout.createSequentialGroup()

.add(jLabel5)

.add(40, 40, 40)

.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jPanel2Layout.createSequentialGroup()

.add(btnSubmit)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(btnCancel))

.add(txtNarration))))

.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

jPanel2Layout.setVerticalGroup(

jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jPanel2Layout.createSequentialGroup()

.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jLabel1)

.add(txtDate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(10, 10, 10)

.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jLabel2)

.add(legerAcctCompletionUI, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jLabel3)

.add(txtAmount, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(jcombDC, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jLabel5)

.add(txtNarration, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(btnSubmit)

.add(btnCancel)))

);

btnClearCheque.setText("Clear this cheque");

btnClearCheque.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnClearChequeActionPerformed(evt);

}

});

jLabel6.setText("Bank balance as per Books");

txtBankBalBook.setEditable(false);

txtBankBalBook.addFocusListener(new java.awt.event.FocusAdapter() {

public void focusGained(java.awt.event.FocusEvent evt) {

txtBankBalBookFocusGained(evt);

}

});

jLabel7.setText("Bank balance as per Bank records");

txtBankBalRecords.addFocusListener(new java.awt.event.FocusAdapter() {

public void focusGained(java.awt.event.FocusEvent evt) {

txtBankBalRecordsFocusGained(evt);

}

public void focusLost(java.awt.event.FocusEvent evt) {

txtBankBalRecordsFocusLost(evt);

}

});

jLabel8.setText("Unreconciled Amount");

txtUnreConAmt.setEditable(false);

txtUnreConAmt.addFocusListener(new java.awt.event.FocusAdapter() {

public void focusGained(java.awt.event.FocusEvent evt) {

txtUnreConAmtFocusGained(evt);

}

});

btnSubmitStatment.setText("Submit this statement");

btnSubmitStatment.setNextFocusableComponent(btnClearCheque);

btnSubmitStatment.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnSubmitStatmentActionPerformed(evt);

}

});

jLabel4.setText("Cheques not cleared");

txtChequeNotClered.setEditable(false);

txtChequeNotClered.addFocusListener(new java.awt.event.FocusAdapter() {

public void focusGained(java.awt.event.FocusEvent evt) {

txtChequeNotCleredFocusGained(evt);

}

});

org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jPanel1Layout.createSequentialGroup()

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)

.add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1)

.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1Layout.createSequentialGroup()

.add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)

.add(jPanel1Layout.createSequentialGroup()

.add(btnClearCheque, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(btnSubmitStatment))

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jPanel1Layout.createSequentialGroup()

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)

.add(org.jdesktop.layout.GroupLayout.LEADING, jLabel7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(org.jdesktop.layout.GroupLayout.LEADING, jLabel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(org.jdesktop.layout.GroupLayout.LEADING, jLabel8))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)

.add(txtBankBalRecords)

.add(txtUnreConAmt)

.add(org.jdesktop.layout.GroupLayout.TRAILING, txtBankBalBook, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)

.add(txtChequeNotClered, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)))

.add(jLabel6)))))

.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 167, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jPanel1Layout.createSequentialGroup()

.add(15, 15, 15)

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)

.add(jLabel4)

.add(txtChequeNotClered, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(15, 15, 15)

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)

.add(jLabel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(txtBankBalBook, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(15, 15, 15)

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jLabel7)

.add(txtBankBalRecords, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(16, 16, 16)

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jLabel8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(txtUnreConAmt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 9, Short.MAX_VALUE)

.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(btnSubmitStatment)

.add(btnClearCheque))

.add(9, 9, 9))

.add(jPanel1Layout.createSequentialGroup()

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))

.addContainerGap())

);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);

this.setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 556, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

);

layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 393, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

);

}// </editor-fold>//GEN-END:initComponents

private void legerAcctCompletionUIFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_legerAcctCompletionUIFocusLost

// TODO add your handling code here:

}//GEN-LAST:event_legerAcctCompletionUIFocusLost

private void legerAcctCompletionUIFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_legerAcctCompletionUIFocusGained

// TODO add your handling code here:

}//GEN-LAST:event_legerAcctCompletionUIFocusGained

private void legerAcctCompletionUIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_legerAcctCompletionUIActionPerformed

// TODO add your handling code here:

if(evt.getSource()==legerAcctCompletionUI)

{

LedgerDetail element = (LedgerDetail) controller.getLedgerDetailsByName(legerAcctCompletionUI.getValue().trim());

Id = element.getID();

if (func.isGroupType(element.getGroupId(), this.controller.getlgroupInfo(), Constants.DebtorGroup,

ASController.getDefault().getAllLedgerGroupDetailsByRefid())) {

this.DebtorCreditor = "D";

}

if (func.isGroupType(element.getGroupId(), this.controller.getlgroupInfo(), Constants.CreditorGroup,

ASController.getDefault().getAllLedgerGroupDetailsByRefid())) {

this.DebtorCreditor = "C";

}

if ((func.isGroupType(element.getGroupId(), this.controller.getlgroupInfo(), Constants.DebtorGroup,

ASController.getDefault().getAllLedgerGroupDetailsByRefid()) == false)

& (func.isGroupType(element.getGroupId(), this.controller.getlgroupInfo(), Constants.CreditorGroup,

ASController.getDefault().getAllLedgerGroupDetailsByRefid())) == false) {

this.DebtorCreditor = null;

}

}

}//GEN-LAST:event_legerAcctCompletionUIActionPerformed

private void jcombDCItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcombDCItemStateChanged

// TODO add your handling code here:

if(evt.getSource()==jcombDC)

{

debitCredit=jcombDC.getSelectedItem().toString();

}

}//GEN-LAST:event_jcombDCItemStateChanged

public void addKeyListener()

{

KeyStroke k2 = KeyStroke.getKeyStroke(KeyEvent.VK_S,

InputEvent.CTRL_MASK);

ActionListener submitListener=new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnSubmitActionPerformed(evt);

}

};

btnSubmit.registerKeyboardAction(submitListener,k2,WHEN_IN_FOCUSED_WINDOW);

KeyStroke k3 = KeyStroke.getKeyStroke(KeyEvent.VK_W,

InputEvent.CTRL_MASK);

ActionListener closeListener=new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnCancelActionPerformed(evt);

}

};

btnCancel.registerKeyboardAction(closeListener,k3,JComponent.WHEN_IN_FOCUSED_WINDOW);

model.addTableModelListener(new TableModelListener() {

public void tableChanged(TableModelEvent e) {

DisplayTable.updateUI();

System.out.println("update suceessfuuly");

}

});

}

private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed

// TODO add your handling code here:

int result = JOptionPane.showConfirmDialog(parent, "Do you want" + " to close this Form ", "cancel",

JOptionPane.YES_NO_OPTION);

if (result == JOptionPane.YES_OPTION)

{

parent.close();

clearUi();

}

else

{

return;

}

}//GEN-LAST:event_btnCancelActionPerformed

private void txtChequeNotCleredFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtChequeNotCleredFocusGained

// TODO add your handling code here:

}//GEN-LAST:event_txtChequeNotCleredFocusGained

private void txtUnreConAmtFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtUnreConAmtFocusGained

// TODO add your handling code here:

}//GEN-LAST:event_txtUnreConAmtFocusGained

private void txtBankBalRecordsFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtBankBalRecordsFocusGained

// TODO add your handling code here:

}//GEN-LAST:event_txtBankBalRecordsFocusLost

private void txtBankBalRecordsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtBankBalRecordsFocusGained

//TODO add your handling code here:

setUnreconciledAmt();

}

private void txtBankBalBookFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtBankBalBookFocusGained

// TODO add your handling code here:

}//GEN-LAST:event_txtBankBalBookFocusGained

private void txtNarrationFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtNarrationFocusGained

// TODO add your handling code here:

}//GEN-LAST:event_txtNarrationFocusGained

private void jcombDCFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jcombDCFocusGained

// TODO add your handling code here:

}//GEN-LAST:event_jcombDCFocusGained

private void txtAmountFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtAmountFocusGained

// TODO add your handling code here:

txtAmount.selectAll();

}//GEN-LAST:event_txtAmountFocusGained

private void txtAmountFocusLost(java.awt.event.FocusEvent evt) {

//TODO add your handling code here:

try

{

txtAmount.setText(decplaces.setNoofDecPlaces(noOfDecPlaces, txtAmount.getText()).toString());

}

catch (Exception e) {

e.printStackTrace();

}

}//

private void DisplayTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DisplayTableMouseClicked

// TODO add your handling code here:

if(evt.getSource()==DisplayTable)

{

JTable target = (JTable) evt.getSource();

selectedRow = target.getSelectedRow();

if(model.getValueAt(selectedRow,6)!=null)

btnClearCheque.setText("Unclear this cheque");

else

btnClearCheque.setText("Clear this cheque");

}

}//GEN-LAST:event_DisplayTableMouseClicked

private void btnSubmitStatmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitStatmentActionPerformed

// TODO add your handling code here:

if(model.dataVector!=null)

{

Vector InfoVec=new Vector();

for(int i=1;i<model.getRowCount();i++)

{

FourColumn element=new FourColumn();

try

{

element.setTranId(Integer.parseInt(model.getValueAt(i,8).toString()));

}

catch (Exception e)

{

element.setTranId(0);

}

if(model.getValueAt(i,6)!=null)

element.setChequeCleared(model.getValueAt(i,6).toString());

else

element.setChequeCleared(null);

InfoVec.add(element);

}

GenericResponse createGenRes=new GenericResponse();

createGenRes.setResponseId(Constants.BANK_RECON_DATA_RECEIVED);

createGenRes.setGenericVector(InfoVec);

createGenRes.setName("BRDATA");

controller.sendMessage(createGenRes);

}

setSubmitStatementButton(false);

}//GEN-LAST:event_btnSubmitStatmentActionPerformed

private void btnClearChequeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearChequeActionPerformed

// TODO add your handling code here:

if(model.getValueAt(selectedRow,2)==null)

{

String msg="Cheque number not available for this entry";

JOptionPane.showMessageDialog(this, msg, "Error", JOptionPane.ERROR_MESSAGE);

return;

}

FourColumn modifyVal=(FourColumn)model.getRow(selectedRow);

if(btnClearCheque.getText().equals("Clear this cheque"))

{

modifyVal.setChequeCleared("Y");

btnClearCheque.setText("Unclear this cheque");

}

else

{

modifyVal.setChequeCleared(null);

btnClearCheque.setText("Clear this cheque");

}

model.TableChanged();

//get Seletion MOdel of table

ListSelectionModel selectionModel =DisplayTable.getSelectionModel();

//select row of tabel

selectionModel.setSelectionInterval(selectedRow,selectedRow);

TableCellRenderer table=DisplayTable.getCellRenderer(selectedRow,2);

Component c=DisplayTable.prepareRenderer(table,selectedRow,2);

if(model.getValueAt(selectedRow,6).toString().equals("Y"))

{

c.setForeground(Color.red);

System.out.println("color set");

}

DisplayTable.updateUI();

setChequeNOtClearTotal();

}//GEN-LAST:event_btnClearChequeActionPerformed

public class CustomTableCellRenderer extends DefaultTableCellRenderer

{

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)

{

Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

if(isSelected)

{

if(model.getValueAt(row,6)!=null)

{

if(row==selectedRow)

{

cell.setForeground( Color.red );

}

}

}

return cell;

}

}

public class mycellrenderer extends JTable

{

public Component prepareRenderer(

final TableCellRenderer renderer, final int row, final int column) {

Component c = super.prepareRenderer(renderer, row, column);

boolean selected = isRowSelected(row);

if( selected )

{

if(model.getValueAt(selectedRow,6)!=null)

c.setForeground(Color.red);

}

return c;

}

}

private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitActionPerformed

// TODO add your handling code here:

if(evt.getSource()==btnSubmit)

{

if(legerAcctCompletionUI.getValue().trim().length() ==0)

{

String msg = "Please Select the Account name";

JOptionPane.showMessageDialog(this, msg, "Error", JOptionPane.ERROR_MESSAGE);

legerAcctCompletionUI.requestFocus();

return;

}

if (txtAmount.getText().length() == 0) {

JOptionPane.showMessageDialog(this, "Invalid Data Entry Add" + "Operation Cannot be performed",

"Error", JOptionPane.ERROR_MESSAGE);

return;

}

if (txtAmount.getText().startsWith("-") == true) {

JOptionPane.showMessageDialog(this, "Value of amount can't be Negative", "error",

JOptionPane.ERROR_MESSAGE);

txtAmount.selectAll();

txtAmount.requestFocus();

return;

}

if(jcombDC.getSelectedItem().toString().equals("Dr"))

{

this.debitCredit="Dr";

sendPaymentTypeVoucher();

}

else

{

this.debitCredit="Cr";

sendReciptTypeVoucher();

}

setSubmitButton(false);

}

}//GEN-LAST:event_btnSubmitActionPerformed

public void sendPaymentTypeVoucher()

{

PaymentValidation obj = new PaymentValidation();

String msg = "Enter Date Between the Current Finanicial Year ";

if (obj.dateValidation(Utility.toSqlDate(txtDate.getDate()), FinancYrTo, this.BooksBeg) == false) {

JOptionPane.showMessageDialog(this, msg, "Error", JOptionPane.ERROR_MESSAGE);

return;

}

Vector VocInfo=new Vector();

VouDetail vouch = new VouDetail();

vouch.setStatus("D");

vouch.setAmt(new BigDecimal(txtAmount.getText()));

if (txtNarration.getText()!= null) {

if (txtNarration.getText().length() == 0) {

vouch.setNrrtn(null);

} else {

vouch.setNrrtn(txtNarration.getText());

}

}

vouch.setAcName(legerAcctCompletionUI.getValue().trim());

vouch.setLID(Id);

VocInfo.add(vouch);

CreateVoucher CreateVoucherRequest = new CreateVoucher();

CreateVoucherRequest.setVdetail(VocInfo);

this.tempVoucInfo=CreateVoucherRequest.getVdetail();

try {

CreateVoucherRequest.setVdt(Utility.toSqlDate(txtDate.getDate()));

this.tempVoucDate=txtDate.getDate();

}

catch (Exception e)

{

JOptionPane.showMessageDialog(this, "please enter the valid date", "Error", JOptionPane.ERROR_MESSAGE);

return;

}

CreateVoucherRequest.setbankCash(bankCash);

CreateVoucherRequest.setVtyp("P");

CreateVoucherRequest.setAutoID(BankID);

CreateVoucherRequest.setBankReconKey("BR");

controller.sendMessage(CreateVoucherRequest);

}

public void sendReciptTypeVoucher()

{

ReceiptValidation obj = new ReceiptValidation();

String msg = "Enter Date Between the Current Finanicial Year ";

if (obj.dateValidation(Utility.toSqlDate(txtDate.getDate()), FinancYrTo, this.BooksBeg) == false) {

JOptionPane.showMessageDialog(this, msg, "Error", JOptionPane.ERROR_MESSAGE);

return;

}

Vector VocInfo=new Vector();

VouDetail vouch = new VouDetail();

vouch.setStatus("C");

vouch.setAmt(new BigDecimal(txtAmount.getText()));

if (txtNarration.getText()!= null) {

if (txtNarration.getText().length() == 0) {

vouch.setNrrtn(null);

} else {

vouch.setNrrtn(txtNarration.getText());

}

}

vouch.setAcName(legerAcctCompletionUI.getValue().trim());

vouch.setLID(Id);

VocInfo.add(vouch);

CreateVoucher CreateVoucherRequest = new CreateVoucher();

CreateVoucherRequest.setVdetail(VocInfo);

this.tempVoucInfo=CreateVoucherRequest.getVdetail();

try {

CreateVoucherRequest.setVdt(Utility.toSqlDate(txtDate.getDate()));

this.tempVoucDate=txtDate.getDate();

}

catch (Exception e)

{

JOptionPane.showMessageDialog(this, "please enter the valid date", "Error", JOptionPane.ERROR_MESSAGE);

return;

}

CreateVoucherRequest.setbankCash(bankCash);

CreateVoucherRequest.setVtyp("R");

CreateVoucherRequest.setAutoID(BankID);

CreateVoucherRequest.setBankReconKey("BR");

controller.sendMessage(CreateVoucherRequest);

}

// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.JTable DisplayTable;

private javax.swing.JButton btnCancel;

private javax.swing.JButton btnClearCheque;

private javax.swing.JButton btnSubmit;

private javax.swing.JButton btnSubmitStatment;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel jLabel5;

private javax.swing.JLabel jLabel6;

private javax.swing.JLabel jLabel7;

private javax.swing.JLabel jLabel8;

private javax.swing.JPanel jPanel1;

private javax.swing.JPanel jPanel2;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JComboBox jcombDC;

//private javax.swing.JTextField legerAcctCompletionUI;

private CompletionUI legerAcctCompletionUI;

private javax.swing.JTextField txtAmount;

private javax.swing.JTextField txtBankBalBook;

private javax.swing.JTextField txtBankBalRecords;

private javax.swing.JTextField txtChequeNotClered;

//private javax.swing.JTextField txtDate;

private DateControl txtDate;

//private javax.swing.JTextField txtNarration;

private AutoFillTextField txtNarration;

private javax.swing.JTextField txtUnreConAmt;

// End of variables declaration//GEN-END:variables

public void CompData() {

CompInfo = new Vector();

CompInfo = controller.getCompInfo();

if (CompInfo != null) {

for (int i = 0; i >< CompInfo.size(); i++) {

CompDetail element = (CompDetail) CompInfo.elementAt(i);

if (element.getID() == ASController.getDefault().getCompid()) {

noOfDecPlaces = element.getdplcs();

FinancYrTo=element.getFinancToYr();

BooksBeg=element.getBBD();

}

}

}

}

public void setTableData(Vector tabledetail)

{

if(model.dataVector !=null) //By preet:- This code delete data from table

{

if(model.dataVector.size()!=0)

{

model.clear();

}

}

this.tabledetail=tabledetail;

System.out.println("dec palces bal:-"+noOfDecPlaces);

FourColumn setOpeningVal = new FourColumn();

setOpeningVal.setAccountName("Opening Balance");

String DATE_FORMAT = "dd-MM-yyyy";

java.text.SimpleDateFormat sdf= new java.text.SimpleDateFormat(DATE_FORMAT);

if(getOpb().compareTo(new BigDecimal("0"))==-1)

{

// setOpeningVal.setTotal(decplaces.setNoofDecPlaces(noOfDecPlaces,getOpb()));

setOpeningVal.setTotal(getOpb());

}

else

{

//setOpeningVal.setTotal(decplaces.setNoofDecPlaces(noOfDecPlaces,getOpb()));

setOpeningVal.setTotal(getOpb());

}

model.addRow(setOpeningVal);

if(this.tabledetail!=null)

{

for(int i=0;i<this.tabledetail.size();i++)

{

FourColumn element=(FourColumn)this.tabledetail.elementAt(i);

FourColumn newVal=new FourColumn();

newVal.SetDate(element.GetDate());

LedgerDetail ledElement=controller.getLedgerDetailsById(element.GetLedId());

newVal.setAccountName(ledElement.getName());

System.out.println("check no:-"+element.getChequeNo());

System.out.println("check clear:-"+element.getChequeCleared());

newVal.setChequeNo(element.getChequeNo());

if(element.getDebit().compareTo(new BigDecimal("0"))!=0)

{

newVal.setDebit(decplaces.setNoofDecPlaces(noOfDecPlaces,element.getDebit()));

// newVal.setDebit(element.getDebit());

}

else if(element.getCredit().compareTo(new BigDecimal("0"))!=0)

{

newVal.setCredit(decplaces.setNoofDecPlaces(noOfDecPlaces,element.getCredit()));

//newVal.setCredit(element.getCredit());

}

newVal.setChequeCleared(element.getChequeCleared());

if(element.getDebit().compareTo(new BigDecimal("0"))!=0)

{

newVal.setTotal(decplaces.setNoofDecPlaces(noOfDecPlaces,getOpb().subtract(element.getDebit())));

}

else if(element.getCredit().compareTo(new BigDecimal("0"))!=0)

{

newVal.setTotal(decplaces.setNoofDecPlaces(noOfDecPlaces,getOpb().add(element.getCredit())));

}

newVal.SetLedId(element.GetLedId());

newVal.setTranId(element.getTranId());

model.addRow(newVal);

}

DisplayTable.setModel(model);

}

setChequeNOtClearTotal();

setBankBalasPerBooks();

setBankBalasPerRecords();

setUnreconciledAmt();

}

private void setUnreconciledAmt()

{

BigDecimal unReConAmt=new BigDecimal(0.0);

try{

unReConAmt=setBankBalasPerBooks().subtract(setBankBalasPerRecords());

}catch(Exception e)

{

unReConAmt=setBankBalasPerBooks().subtract(new BigDecimal(0.0));

}

txtUnreConAmt.setText(decplaces.setNoofDecPlaces(noOfDecPlaces,unReConAmt).toString());

}

private BigDecimal setBankBalasPerRecords()

{

BigDecimal bankBalperRec=getNetBalForChequeNotCleared().add(new BigDecimal(txtBankBalBook.getText()));

txtBankBalRecords.setText(decplaces.setNoofDecPlaces(noOfDecPlaces,bankBalperRec).toString());

return bankBalperRec;

}

private BigDecimal setBankBalasPerBooks()

{

BigDecimal totalAmt=new BigDecimal(0.0);

if(model.dataVector !=null)

{

try

{

LedgerDetail ledelement=controller.getLedgerDetailsById(BankID);

totalAmt=ledelement.getCbal();

}

catch (Exception e) {e.printStackTrace();}

}

txtBankBalBook.setText(decplaces.setNoofDecPlaces(noOfDecPlaces,totalAmt).toString());

return totalAmt;

}

private void setChequeNOtClearTotal()

{

txtChequeNotClered.setText(getNetBalForChequeNotCleared().toString());

}

private BigDecimal getDebitTotal()

{

BigDecimal totalAmt=new BigDecimal(0.0);

if(model.dataVector !=null)

{

for(int i=1;i<model.getRowCount();i++)

{

if(model.getValueAt(i,6)==null&&model.getValueAt(i,2)!=null)

{

BigDecimal temp=new BigDecimal(0.0);

try{

temp=new BigDecimal(model.getValueAt(i,3).toString());

}

catch (Exception e){}

totalAmt=totalAmt.add(temp);

}

}

}

return totalAmt;

}

private BigDecimal getCreditTotal()

{

BigDecimal totalAmt=new BigDecimal(0.0);

if(model.dataVector !=null)

{

for(int i=1;i<model.getRowCount();i++)

{

if(model.getValueAt(i,6)==null&&model.getValueAt(i,2)!=null)

{

BigDecimal temp=new BigDecimal(0.0);

try{

temp=new BigDecimal(model.getValueAt(i,4).toString());

}

catch (Exception e){}

totalAmt=totalAmt.add(temp);

}

}

}

return totalAmt;

}

private BigDecimal getNetBalForChequeNotCleared()

{

BigDecimal totalAmt=new BigDecimal(0.0);

totalAmt=getCreditTotal().add(getDebitTotal());

return totalAmt;

}

class TableModel extends AbstractTableModel{

/**

* The ><code>Vector</code> of <code>Vectors</code> of <code>Object</code> values.

*/

private Vector dataVector;

/**

* Number of the columns visible in the table. -1 means all the columsn are visible.

*/

private int visibleColumnCount = -1;

/**

* This array contains the column headers.

*/

private String columns[] = new String[] {};

/**

* Returns false regardless of parameter values resulting in a non editable table.

*

*/

public boolean isCellEditable(int nRow, int nCol) {

if(nCol==2)

return true;

else

return false;

}

/**

* Specifies the classes associated with the table model .

*/

// String[] columnNames = { "Date", "Invoice No", "Due Date", "Amount", "Paymnet", "Net Balance" };

Class columnClasses[] = { Date.class, String.class, String.class,BigDecimal.class,BigDecimal.class,BigDecimal.class,String.class,Integer.class,Integer.class};

/**

* Returns the <code>Object</code> that contains the table's data values. The object represents a single row

* of values.

*

*/

public Object getRow(int rowNum) {

if (dataVector == null || rowNum > dataVector.size())

return null;

else

return dataVector.elementAt(rowNum);

}

/**

* Adds a row to the end of the model. The new row will contain <code>null</code> values unless

* <code>rowData</code> is specified. Notification of the row being added will be generated.

*

* @param row optional data of the row being added

*/

public void addRow(Object row) {

if (dataVector == null) {

dataVector = new Vector();

}

dataVector.add(row);

// fire the event to the ui informing it that the row has been added

// to the model.

fireTableRowsInserted(dataVector.size(), dataVector.size());

}

public void clear() {

try{

dataVector.clear();

}catch(Exception e)

{

}

fireTableChanged(null);

}

public void TableChanged() {

// dataVector.clear();

fireTableChanged(null);

}

public void deleteRow(int rowNum) {

dataVector.remove(rowNum);

// fire the event to the ui informing it that the row has been

// deleted from the model.

fireTableRowsDeleted(dataVector.size(), dataVector.size());

}

/**

* Returns an attribute value for the cell at <code>row</code> and <code>column</code>. This is an

* important method as it will return the mapping of the column number with its values. also the value should be

* returned properly so that the table could render it.

*

* @param row the row whose value is to be queried

* @param column the column whose value is to be queried

* @return the value Object at the specified cell

* @exception ArrayIndexOutOfBoundsException if an invalid row or column was given

*/

public Object getValueAt(int nRow, int nCol) {

if (nRow < 0 || nRow >= getRowCount())

return "";

FourColumn row = (FourColumn) dataVector.elementAt(nRow);

switch (nCol) {

case 0:

return row.GetDate();

case 1:

return row.getAccountName();

case 2:

return row.getChequeNo();

case 3:

return row.getDebit();

case 4:

return row.getCredit();

case 5:

return row.getTotal();

case 6:

return row.getChequeCleared();

case 7:

return row.GetLedId();

case 8:

return row.getTranId();

}

return "";

}

/**

* Returns the number of rows in this data table.

*

* @return the number of rows in the model

*/

public int getRowCount() {

return dataVector == null ? 0 : dataVector.size();

}

/**

* Returns the number of columns to be visible in this data table. If the visible count is not set then default

* to all the columns

*

* @return the number of visible columns in the model

*/

public int getColumnCount() {

if (visibleColumnCount > -1)

return visibleColumnCount;

else

return columns.length;

}

/**

* Returns the column name.

*

* @return a name for this column using the string value of the appropriate member in

* <code>columnIdentifiers</code>. If <code>columnIdentifiers</code> does not have an entry for

* this index, returns the default name provided by the superclass

*/

public String getColumnName(int col) {

if (col < columns.length) {

return columns[col];

} else {

return null;

}

}

public Class getColumnClass(int c) {

return columnClasses[c];

}

/**

* Sets the visible number of Columns in this table model.

*

* @param visibleColumnCount

*/

public void setVisibleColumnCount(int visibleColumnCount) {

this.visibleColumnCount = visibleColumnCount;

}

/**

* Get the Column headers.

*

* @return

*/

public String[] getColumns() {

return columns;

}

/**

* Sets the column headers.

*

* @param columns

*/

public void setColumns(String[] columns) {

this.columns = columns;

}

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

bookVector getVal=(bookVector)dataVector.elementAt(row);

getVal.setInitialInvoiceNo(Integer.parseInt(value.toString()));

fireTableCellUpdated(row, col);

}*/

}

public void clearUi()

{

if(model.dataVector !=null)

{

if(model.dataVector.size()!=0)

{

model.clear();

}

}

txtAmount.setText("");

legerAcctCompletionUI.setValue("");

txtNarration.setText("");

txtBankBalBook.setText("");

txtBankBalRecords.setText("");

txtUnreConAmt.setText("");

txtChequeNotClered.setText("");

setSubmitButton(true);

setSubmitStatementButton(true);

}

public BigDecimal getOpb() {

return opb;

}

public void setOpb(BigDecimal opb) {

this.opb = opb;

}

public int getTransactionId() {

return transactionId;

}

/*

* Method called when voucher entry submit from this form server send transaction id against this voucher

* and this voucher entry set in table

*/

public void setTransactionId(int transactionId) {

this.transactionId = transactionId;

setNewVoucEntryInTable();

legerAcctCompletionUI.setValue("");

txtAmount.setText("0.0");

txtNarration.setText("");

}

private void setNewVoucEntryInTable()

{

if(this.tempVoucInfo!=null)

{

FourColumn newVal=new FourColumn();

VouDetail element=(VouDetail)tempVoucInfo.elementAt(0);

newVal.SetDate(tempVoucDate);

newVal.setAccountName(element.getAcName());

newVal.setChequeNo("");

if(this.debitCredit.equals("Dr"))

{

newVal.setDebit(element.getAmt());

newVal.setTotal(getOpb().subtract(element.getAmt()));

}

else

{

newVal.setCredit(element.getAmt());

newVal.setTotal(getOpb().add(element.getAmt()));

}

newVal.setChequeCleared(null);

newVal.SetLedId(element.getLID());

newVal.setTranId(this.transactionId);

model.addRow(newVal);

DisplayTable.setModel(model);

}

setChequeNOtClearTotal();

setBankBalasPerBooks();

setUnreconciledAmt();

}

public int getBankID() {

return BankID;

}

public void setBankID(int bankID) {

BankID = bankID;

try{

LedgerDetail element = controller.getLedgerDetailsById(bankID);

if (func.isGroupType(element.getGroupId(), this.controller.getlgroupInfo(), Constants.BankGroup,

ASController.getDefault().getAllLedgerGroupDetailsByRefid())) {

this.bankCash = "B";

}else if (func.isGroupType(element.getGroupId(), this.controller.getlgroupInfo(), Constants.WorkingCapitalLoanGroup,

ASController.getDefault().getAllLedgerGroupDetailsByRefid())) {

this.bankCash = "B";

}

}

catch (Exception e)

{

e.printStackTrace();

}

}

public boolean isSubmitButton() {

return submitButton;

}

public void setSubmitButton(boolean submitButton) {

this.submitButton = submitButton;

btnSubmit.setEnabled(submitButton);

}

public boolean isSubmitStatementButton() {

return submitStatementButton;

}

public void setSubmitStatementButton(boolean submitStatementButton) {

this.submitStatementButton = submitStatementButton;

btnSubmitStatment.setEnabled(submitStatementButton);

}

public void setRefreshedNarrationData()

{

txtNarration.setAutoFillVec(getNarrationData());

}

}

socmaga at 2007-7-12 23:14:43 > top of Java-index,Desktop,Core GUI APIs...
# 7

Here is the code that creates the JTable:

DisplayTable = new javax.swing.JTable();

To override method "prepareRenderer", replace your code line with this:

DisplayTable = new javax.swing.JTable(){

public Component prepareRenderer(

final TableCellRenderer renderer, final int row, final int column) {

Component c = super.prepareRenderer(renderer, row, column);

... here comes the custom code, as I showed in the Example already above

return c;

}

};

EDIT: You don't have to call the method prepareRenderer, because it is automatically called by the JTable API.

Message was edited by:

Andre_Uhres

Andre_Uhresa at 2007-7-12 23:14:43 > top of Java-index,Desktop,Core GUI APIs...