Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

L Sankaranarayanan

Greenhorn
+ Follow
since Dec 13, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by L Sankaranarayanan


I have found it! there is color code missing in printable. is missing . When added, it works ! Thank you all guys!
9 years ago
I have one printpreview program taken from net . It actually takes one printable object and shows the preview one or multiple pages. My printable class is nothing but displaying text in more than one pages. But preview shows empty pages .
PrintPreview Code goes here



My Printable class is given here It works fine with any printers. But preview is not possible in this case. Other page wise preview program shows the output. Why this printpreview does not show the preview?









Cany any one provide solution for this? I dont want Page wise printpreview but what i want is globlal preview ie all pages at one time

L.Sankaranarayanan. Srivilliputtur
9 years ago
Two things you should do
STEP1 .You should instantiate an Account object at the beginning as shown below




STEP 2: Change actionListener method as follows




There is another easy way .We can define our business logic in the BankAccount class by writing a method


9 years ago
Thanks Mr.Renganathan.

What I actually want is EmployeePickList Class with a JTable. The table must initially contain 10 empty rows. When we type some letters in the search TextField , employee names should appear (TextField is added with Document Listener) . By empty constructor I make 10 rows by default. Any how I found the solution by modifiying my codes in the insertEmployee method

corrected code segment



Thanks once again . Im new to this forum and so I didn't notice the code tag . I'll correct myself in future




9 years ago
I wish to construct a JTable with 10 rows defaults . My table model uses ArrayList and Employee objects. When I use it JTable the data is inserted in the last row Why? Could any help me

My code is





import java.util.Date;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import javax.swing.*;
import java.util.*;
/**
*
* @author L.Sankaranarayanan
*/



public class EmployeeTableModel extends AbstractTableModel{
private static final long serialVersionUID = 1L;
protected static final int EMPLOYEE_ID =0;
protected static final int EMPLOYEEE_NAME =1;
protected static final int DATE_OF_BIRTH =2;
protected static final int ADDRESS =3;
protected static final int CITY =4;
protected static final int PINCODE =5;
protected static final int CONTACT_NUMBER =6;
protected static final int DEPARTMENT=7;
protected static final int DATE_OF_APPOINTMENT=8;
protected static final int PASSWORD =9;



protected String employeeId;
protected String employeeName;

protected java.sql.Date dateOfBirth;
protected String address;
protected String city;
protected String pinCode;
protected String contactNumber;
protected String department;
protected java.sql.Date dateOfAppointment;
protected String password;

private int rows;



static final public ColumnData columnHeads[] = {

new ColumnData( "Id", 30, JLabel.LEFT ),
new ColumnData( "Name", 100, JLabel.LEFT ),
new ColumnData( "DateOfBirth", 60, JLabel.RIGHT ),
new ColumnData( "Address", 100, JLabel.LEFT),
new ColumnData( "City", 100, JLabel.LEFT),
new ColumnData( "Pincode", 100, JLabel.LEFT),
new ColumnData( "ContactNumber", 100, JLabel.LEFT),
new ColumnData( "Department", 100, JLabel.LEFT),
new ColumnData( "DateOfAppointment", 100, JLabel.LEFT),
new ColumnData( "Password", 100, JLabel.LEFT)};








protected ArrayList<Employee> employees;

public EmployeeTableModel()
{
this.employees = new ArrayList<Employee>();
// createDefaultRows();

}

public EmployeeTableModel(ArrayList<Employee> employees)
{
this.employees = employees;
}



/*

public void createDefaultRows()
{ rows =10;
for( int i = 0; i < rows; i++ )
{
//employees = new ArrayList<Employee>();
//for( int j = 0; j < columns.length; j++ )
// cols.add(new Employe());
employees.add(new Employee());
}


}
*/
public int getRowCount() {
//if( employees.size()==0) return 10;
return employees.size();
}



public int getColumnCount() {
return columnHeads.length;
}



public String getColumnName(int column) {
return columnHeads[column].title;
}

public void removeAllData(){
employees = null;
this.fireTableDataChanged();
}
public void update(ArrayList<Employee> employees){
this.employees=employees;
fireTableDataChanged();
}
public void clear()
{
employees = employees != null ? employees : new ArrayList<Employee>( );

//createDefaultRows();
this.fireTableDataChanged();


}

public Object getValueAt(int rowIndex, int columnIndex) {
Employee emp =employees.get(rowIndex);

System.out.println("Inside getValueAt "+emp);

switch(columnIndex){
case EMPLOYEE_ID :return emp.getEmployeeId();
case EMPLOYEEE_NAME :return emp.getEmployeeName();
case DATE_OF_BIRTH :return emp.getDateOfBirth();
case ADDRESS :return emp.getAddress();
case CITY :return emp.getCity();
case PINCODE :return emp.getPinCode();
case CONTACT_NUMBER :return emp.getContactNumber();
case DEPARTMENT : return emp.getDepartment();
case DATE_OF_APPOINTMENT:return emp.getDateOfAppointment();
case PASSWORD :return emp.getPassword();

default: return "";
}
}

@Override
public Class<?> getColumnClass(int columnIndex) {
switch(columnIndex)
{

case EMPLOYEE_ID :return String.class;
case EMPLOYEEE_NAME :return String.class;
case DATE_OF_BIRTH :return Date.class;
case ADDRESS :return String.class;
case CITY :return String.class;
case PINCODE :return String.class;
case CONTACT_NUMBER :return String.class;
case DEPARTMENT : return String.class;
case DATE_OF_APPOINTMENT:return Date.class;
case PASSWORD :return String.class;

default: return Object.class;
}
}
//over ride the following method only if you want the table cells editable

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

Person p = data.get(row);
switch (col) {
case 0: break;
case 1: p.setFirstName( (String) value); break;
case 2: p.setSurName( (String) value); break;
case 3: p.getEventBirth().setDate( (Date) value); break;
case 4: p.getEventDeath().setDate( (Date) value); break;
case 5: p.setInfo( (String) value); break;
default: break;
}

}
*/





public Employee getEmployeeAt( int row )
{
if( row >= getRowCount( ))
return null;

return employees.get(row);
}







public void insert(Employee employee)
{
employees.add(employee);
fireTableRowsInserted(getRowCount()-9,getRowCount()-9);
// super.fireTableDataChanged();

}
public void update(Employee employee, int index)
{
employees.set(index, employee);
fireTableRowsUpdated(index,index);
}
public void delete(int index)
{
employees.remove(index);
fireTableRowsDeleted(index,index);
}






public void setEmployees(ArrayList<Employee> employees)
{
this.employees = employees;
fireTableDataChanged();
}

public ArrayList<Employee> getEm ployees()
{
return this.employees;
}


}








[/color]



9 years ago
Thanks for your reply Now I have understood the power of GridBagLayout. Thanks once again
9 years ago
Can any one help me to achieve the effects of GridBagLayout Manager without setting Layout(null) or grouping so many JPanels?Is there any equivalent Layouts in Java?
9 years ago

Darryl Burke wrote:Pretty nearly every layout manager except GridLayout shows components at differing sizes. Take your pick: A Visual Guide to Layout Managers




But what I asked is other than null Layout JTextField should be its original size even when expanded.
9 years ago
Which is the best Layout Manager to arrange JTextFileds of different sizes other than GridBagLayout?
9 years ago