Bourke
asked on
Updating a Jtable
Hi,
I have an app the main window is a JFrame and it has a JInternalFrame in it which is a search window with a Jtable. When i enter my search criteria and hit a button
the Jtable is populated with the results.
I can highlight a row on the JTable and mouseclick which give me a popup menu
I choose one item from this menu and it displays say and update window(JInternalFrame) it allows me to update the details of the record in the Jtable I selected.
when I hit update on this window I want the JTable in the search window to automatically udpdate. Has anyone any ideas?
thanks
V
I have an app the main window is a JFrame and it has a JInternalFrame in it which is a search window with a Jtable. When i enter my search criteria and hit a button
the Jtable is populated with the results.
I can highlight a row on the JTable and mouseclick which give me a popup menu
I choose one item from this menu and it displays say and update window(JInternalFrame) it allows me to update the details of the record in the Jtable I selected.
when I hit update on this window I want the JTable in the search window to automatically udpdate. Has anyone any ideas?
thanks
V
...then on your tableModel call
fireTableRowsUpdated(int firstRow, int lastRow);
e.g.
fireTableRowsUpdated(4, 4); // 4 being the index in the table of the selected and changed item
fireTableRowsUpdated(int firstRow, int lastRow);
e.g.
fireTableRowsUpdated(4, 4); // 4 being the index in the table of the selected and changed item
zzynx,
shouldnt MVC have that under control? Meaning: If we change a value in the model, the controler will notify the view about it? Or do we really need to call fireTableRowsUpdated?
I'v tried it, you dont need no fireTableRowsUpdated call, if you are updating the values in the model. Thats the point of MVC.
TableModel tm = table.getModel();
tm.setValueAt("xxx", x, y); /// this will already make the view repaint the values
>> Meaning: If we change a value in the model, the controler will notify the view about it?
Correct.
>> Or do we really need to call fireTableRowsUpdated?
Depending.
If you use your own table model extending from AbstractTableModel you should use those calls inside your table model (e.g. in the setValue() function)
If you use your own table model extending from DefaultTableModel it is done by using e.g. addRow() & setValueAt()
Correct.
>> Or do we really need to call fireTableRowsUpdated?
Depending.
If you use your own table model extending from AbstractTableModel you should use those calls inside your table model (e.g. in the setValue() function)
If you use your own table model extending from DefaultTableModel it is done by using e.g. addRow() & setValueAt()
>> tm.setValueAt("xxx", x, y); /// this will already make the view repaint the values
As I just told indeed.
Because by default a JTable uses the DefaultTableModel.
Don't know if the author uses his own table model or not.
If he does use the default one, then my first comment applies.
Sorry for the confusion introduced by my 2nd.
As I just told indeed.
Because by default a JTable uses the DefaultTableModel.
Don't know if the author uses his own table model or not.
If he does use the default one, then my first comment applies.
Sorry for the confusion introduced by my 2nd.
ASKER
I use DefaultTableModel.
My prob. is that the table is in one class (Search JInternalFrame) and the
Update is in another class (Update JInternalFrame).
So how do I access the table model in the Search window? pass it
via the constructor of the Update window?
V (I'm a she :o) )
My prob. is that the table is in one class (Search JInternalFrame) and the
Update is in another class (Update JInternalFrame).
So how do I access the table model in the Search window? pass it
via the constructor of the Update window?
V (I'm a she :o) )
yourTableModel = (DefaultTableModel)yourTab le.getMode l();
ASKER
Sorry I still done understand?
My tablemodel is in a different class to where I am updating.
My tablemodel is in a different class to where I am updating.
... then use
yourTableModel.setValueAt( Object aValue, int row, int column);
e.g.
yourTableModel.setValueAt( "New String item", 0, 0); // changes the item shown on the 1st row in the 1st column (assuming it's a String)
yourTableModel.setValueAt(
e.g.
yourTableModel.setValueAt(
ASKER
Will I make it public and shared?
I was trying to say that if you have your JTable object (I guess you have it in the search window. If not you can pass it)
you can always get the table model behind it.
you can always get the table model behind it.
Replace
JTable object
by
JTable instance (=your table)
JTable object
by
JTable instance (=your table)
>> If not you can pass it
in the constructor or via a function you call on your search window:
public void setTable(JTable theTable) {
this.theTable = theTable;
}
in the constructor or via a function you call on your search window:
public void setTable(JTable theTable) {
this.theTable = theTable;
}
Sorry again. In the above replace "search window" by "update window" of course
:°/
:°/
ASKER
Hi,
I passed the table in via the constructor and just wrote these two lines:
DefaultTableModel dtm = (DefaultTableModel)table.g etModel();
dtm.setValueAt("Changed", selectedRow, 2);
selectedRow is also passed in via the constructor.
But nothing happens???
thanks
V
I passed the table in via the constructor and just wrote these two lines:
DefaultTableModel dtm = (DefaultTableModel)table.g
dtm.setValueAt("Changed", selectedRow, 2);
selectedRow is also passed in via the constructor.
But nothing happens???
thanks
V
>> selectedRow is also passed in via the constructor.
Not needed. You can use
table.getSelectedRow(); // Remark: returns -1 if no selected
>>But nothing happens???
Presumably because your table is not editable
Not needed. You can use
table.getSelectedRow(); // Remark: returns -1 if no selected
>>But nothing happens???
Presumably because your table is not editable
Preparing some demo...
ASKER
this is what I have when constructing the table:
table = new JTable () {
public boolean isCellEditable (int iRows, int iCols) {
return false; //Disable All Columns of Table.
}
};
but I dont want people to be able to edit the rows by highlighting it I do that in
the update window.
Can I make the table editable for the length of time I want to change it
and then disable it again?
V
table = new JTable () {
public boolean isCellEditable (int iRows, int iCols) {
return false; //Disable All Columns of Table.
}
};
but I dont want people to be able to edit the rows by highlighting it I do that in
the update window.
Can I make the table editable for the length of time I want to change it
and then disable it again?
V
>>Can I make the table editable for the length of time I want to change it and then disable it again?
You could try:
table = new JTable () {
public boolean isCellEditable (int iRows, int iCols) {
return busyEditing; // and busyEditing is a flag that is set true when the update window comes up and false when it is closed
}
};
Don't know for sure if it will work, though.
You could try:
table = new JTable () {
public boolean isCellEditable (int iRows, int iCols) {
return busyEditing; // and busyEditing is a flag that is set true when the update window comes up and false when it is closed
}
};
Don't know for sure if it will work, though.
/*
* MyTableModel.java
*
*/
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
/**
*
* @author zzynx
*/
public class MyTableModel extends DefaultTableModel {
List data; // a list of MyObject's
private String[] columnNames = { "Column1", "Column2", "Column3" };
/** Creates a new instance of MyTableModel */
public MyTableModel(List d) {
this.data = d;
}
public Object getTableObject(int index) {
return data.get(index);
}
public void setColumnName(int index, String name) {
if (index < columnNames.length)
columnNames[index] = name;
}
public boolean isCellEditable(int row, int col) {
return false;
}
public void addRow(MyTableObject object) {
data.add(object);
fireTableRowsInserted(data .size()-2, data.size()-2);
}
public void removeRow(int index) {
data.remove(index);
fireTableRowsDeleted(index , index);
}
public Class getColumnClass(int col) {
return super.getColumnClass(col);
}
public int getRowCount() {
return data==null ? 0 : data.size();
}
public int getColumnCount() {
return columnNames.length;
}
public Object getValueAt(int row, int col) {
if ( row < 0 || row >= data.size() ) return null;
MyTableObject myObj = (MyTableObject) data.get(row);
if (col==0)
return myObj.getField1();
else if (col==1)
return myObj.getField2();
else if (col==2)
return myObj.getField3();
else return null;
}
// not needed if not editable:
public void setValueAt(Object value, int row, int col) {
if ( row < 0 || row >= data.size() || col!=0 ) return;
// only col=0 is editable (in this example)
MyTableObject myObj = (MyTableObject) data.get(row);
if (col==0)
myObj.setField1( (String)value );
else if (col==1)
myObj.setField2( (String)value );
else if (col==2)
myObj.setField3( (String)value );
fireTableCellUpdated(row, col);
}
public String getColumnName(int col) {
return columnNames[col];
}
}
/*
* MyObject.java
*
*/
/**
*
* @author zzynx
*/
public class MyTableObject {
private String field1 = "";
private String field2 = "";
private String field3 = "";
/** Creates a new instance of MyTableObject */
public MyTableObject() {
}
public MyTableObject(String f1, String f2, String f3) {
field1 = f1;
field2 = f2;
field3 = f3;
}
public String getField1() { return field1; }
public String getField2() { return field2; }
public String getField3() { return field3; }
public void setField1(String f1) { field1 = f1; }
public void setField2(String f2) { field2 = f2; }
public void setField3(String f3) { field3 = f3; }
}
/*
* TableDemo.java
*
*/
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.util.List;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author zzynx
*/
public class TheTableDemo extends javax.swing.JFrame {
/** Creates new form TableDemo */
public TheTableDemo() {
initComponents();
initTable();
}
private void initTable() {
List data = new ArrayList();
data.add( new MyTableObject("data1", "data2", "data3") );
data.add( new MyTableObject("data2.1", "data2.2", "data2.3") );
data.add( new MyTableObject("data3.1", "data3.2", "data3.3") );
theTable.setModel(new MyTableModel(data));
}
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
theTable = new javax.swing.JTable();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
addButton = new javax.swing.JButton();
deleteButton = new javax.swing.JButton();
changeButton = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapt er() {
public void windowClosing(java.awt.eve nt.WindowE vent evt) {
exitForm(evt);
}
});
jScrollPane1.setViewportVi ew(theTabl e);
getContentPane().add(jScro llPane1, java.awt.BorderLayout.CENT ER);
jPanel1.setLayout(new java.awt.FlowLayout(java.a wt.FlowLay out.RIGHT) );
addButton.setText("Add");
addButton.addActionListene r(new java.awt.event.ActionListe ner() {
public void actionPerformed(java.awt.e vent.Actio nEvent evt) {
addButtonActionPerformed(e vt);
}
});
jPanel2.add(addButton);
deleteButton.setText("Dele te");
deleteButton.addActionList ener(new java.awt.event.ActionListe ner() {
public void actionPerformed(java.awt.e vent.Actio nEvent evt) {
deleteButtonActionPerforme d(evt);
}
});
jPanel2.add(deleteButton);
changeButton.setText("Chan ge");
changeButton.addActionList ener(new java.awt.event.ActionListe ner() {
public void actionPerformed(java.awt.e vent.Actio nEvent evt) {
changeButtonActionPerforme d(evt);
}
});
jPanel2.add(changeButton);
jPanel1.add(jPanel2);
getContentPane().add(jPane l1, java.awt.BorderLayout.SOUT H);
pack();
}
private void changeButtonActionPerforme d(java.awt .event.Act ionEvent evt) {
int selectedRow = theTable.getSelectedRow();
if (selectedRow!=-1) {
MyTableModel model = (MyTableModel)theTable.get Model();
MyTableObject obj = (MyTableObject)model.getTa bleObject( selectedRo w);
obj.setField1("Changed");
obj.setField2("Changed too");
obj.setField3("Also changed...");
model.fireTableRowsUpdated (selectedR ow, selectedRow); // needed
}
}
private void deleteButtonActionPerforme d(java.awt .event.Act ionEvent evt) {
if (theTable.getSelectedRow() !=-1)
((MyTableModel)theTable.ge tModel()). removeRow(
theTable.getSelectedRow() );
}
private void addButtonActionPerformed(j ava.awt.ev ent.Action Event evt) {
((MyTableModel)theTable.ge tModel()). addRow(
new MyTableObject("aaaaa", "bbbbbb", "ccccc") );
}
/** Exit the Application */
private void exitForm(java.awt.event.Wi ndowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
UIManager.setLookAndFeel(U IManager.g etSystemLo okAndFeelC lassName() );
}
catch (Exception e) {
System.exit(0);
}
new TheTableDemo().show();
}
// Variables declaration - do not modify
private javax.swing.JButton addButton;
private javax.swing.JButton changeButton;
private javax.swing.JButton deleteButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable theTable;
// End of variables declaration
}
Run TheTableDemo.
Select an entry in the table and press "change".
* MyTableModel.java
*
*/
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
/**
*
* @author zzynx
*/
public class MyTableModel extends DefaultTableModel {
List data; // a list of MyObject's
private String[] columnNames = { "Column1", "Column2", "Column3" };
/** Creates a new instance of MyTableModel */
public MyTableModel(List d) {
this.data = d;
}
public Object getTableObject(int index) {
return data.get(index);
}
public void setColumnName(int index, String name) {
if (index < columnNames.length)
columnNames[index] = name;
}
public boolean isCellEditable(int row, int col) {
return false;
}
public void addRow(MyTableObject object) {
data.add(object);
fireTableRowsInserted(data
}
public void removeRow(int index) {
data.remove(index);
fireTableRowsDeleted(index
}
public Class getColumnClass(int col) {
return super.getColumnClass(col);
}
public int getRowCount() {
return data==null ? 0 : data.size();
}
public int getColumnCount() {
return columnNames.length;
}
public Object getValueAt(int row, int col) {
if ( row < 0 || row >= data.size() ) return null;
MyTableObject myObj = (MyTableObject) data.get(row);
if (col==0)
return myObj.getField1();
else if (col==1)
return myObj.getField2();
else if (col==2)
return myObj.getField3();
else return null;
}
// not needed if not editable:
public void setValueAt(Object value, int row, int col) {
if ( row < 0 || row >= data.size() || col!=0 ) return;
// only col=0 is editable (in this example)
MyTableObject myObj = (MyTableObject) data.get(row);
if (col==0)
myObj.setField1( (String)value );
else if (col==1)
myObj.setField2( (String)value );
else if (col==2)
myObj.setField3( (String)value );
fireTableCellUpdated(row, col);
}
public String getColumnName(int col) {
return columnNames[col];
}
}
/*
* MyObject.java
*
*/
/**
*
* @author zzynx
*/
public class MyTableObject {
private String field1 = "";
private String field2 = "";
private String field3 = "";
/** Creates a new instance of MyTableObject */
public MyTableObject() {
}
public MyTableObject(String f1, String f2, String f3) {
field1 = f1;
field2 = f2;
field3 = f3;
}
public String getField1() { return field1; }
public String getField2() { return field2; }
public String getField3() { return field3; }
public void setField1(String f1) { field1 = f1; }
public void setField2(String f2) { field2 = f2; }
public void setField3(String f3) { field3 = f3; }
}
/*
* TableDemo.java
*
*/
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.util.List;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author zzynx
*/
public class TheTableDemo extends javax.swing.JFrame {
/** Creates new form TableDemo */
public TheTableDemo() {
initComponents();
initTable();
}
private void initTable() {
List data = new ArrayList();
data.add( new MyTableObject("data1", "data2", "data3") );
data.add( new MyTableObject("data2.1", "data2.2", "data2.3") );
data.add( new MyTableObject("data3.1", "data3.2", "data3.3") );
theTable.setModel(new MyTableModel(data));
}
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
theTable = new javax.swing.JTable();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
addButton = new javax.swing.JButton();
deleteButton = new javax.swing.JButton();
changeButton = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapt
public void windowClosing(java.awt.eve
exitForm(evt);
}
});
jScrollPane1.setViewportVi
getContentPane().add(jScro
jPanel1.setLayout(new java.awt.FlowLayout(java.a
addButton.setText("Add");
addButton.addActionListene
public void actionPerformed(java.awt.e
addButtonActionPerformed(e
}
});
jPanel2.add(addButton);
deleteButton.setText("Dele
deleteButton.addActionList
public void actionPerformed(java.awt.e
deleteButtonActionPerforme
}
});
jPanel2.add(deleteButton);
changeButton.setText("Chan
changeButton.addActionList
public void actionPerformed(java.awt.e
changeButtonActionPerforme
}
});
jPanel2.add(changeButton);
jPanel1.add(jPanel2);
getContentPane().add(jPane
pack();
}
private void changeButtonActionPerforme
int selectedRow = theTable.getSelectedRow();
if (selectedRow!=-1) {
MyTableModel model = (MyTableModel)theTable.get
MyTableObject obj = (MyTableObject)model.getTa
obj.setField1("Changed");
obj.setField2("Changed too");
obj.setField3("Also changed...");
model.fireTableRowsUpdated
}
}
private void deleteButtonActionPerforme
if (theTable.getSelectedRow()
((MyTableModel)theTable.ge
theTable.getSelectedRow() );
}
private void addButtonActionPerformed(j
((MyTableModel)theTable.ge
new MyTableObject("aaaaa", "bbbbbb", "ccccc") );
}
/** Exit the Application */
private void exitForm(java.awt.event.Wi
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
UIManager.setLookAndFeel(U
}
catch (Exception e) {
System.exit(0);
}
new TheTableDemo().show();
}
// Variables declaration - do not modify
private javax.swing.JButton addButton;
private javax.swing.JButton changeButton;
private javax.swing.JButton deleteButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable theTable;
// End of variables declaration
}
Run TheTableDemo.
Select an entry in the table and press "change".
I know the change isn't done in another window, but the idea to apply in that case is the just same.
Offline I go... Success.
ASKER
Hi,
I've been trying to work with your code and what is happening is when I pass the JTable and I want to get the selected row using:
selectedRow = table.getSelectedRow();
it returns -1 when I have selected a row in the table.
I'm passing the table in via the contructor.
I've been trying to work with your code and what is happening is when I pass the JTable and I want to get the selected row using:
selectedRow = table.getSelectedRow();
it returns -1 when I have selected a row in the table.
I'm passing the table in via the contructor.
ASKER
Oh by the way thanks alot for all that code.
>> it returns -1 when I have selected a row in the table
Impossible.
Looks like you perform getSelectedRow() on "another JTable object".
Is it possible to post some relevant code?
Impossible.
Looks like you perform getSelectedRow() on "another JTable object".
Is it possible to post some relevant code?
>> Oh by the way thanks alot for all that code.
No problem.
I hope it gives you an idea of how (flexible it is) to work with a table model.
No problem.
I hope it gives you an idea of how (flexible it is) to work with a table model.
ASKER
Ok
This is in the update:
Constructor:
public UpdateBook(JComponent comp, String user, Connection con, String bookId, JTable table, int selectedRow){
super("Update Book", false, true, false, true);
this.con = con;
this.user = user;
this.comp = comp;
this.table = table;
this.selectedRow = selectedRow;
comp.add(this);
SetUpComponents();
GetBookDetails(bookId);
}
THis is when the Details have been updated:
JOptionPane.showMessageDia log(this, "Book has been updated successfully");
selectedRow = table.getSelectedRow();
JOptionPane.showMessageDia log(this, "Selected Row = " + selectedRow);
if (selectedRow!=-1) {
SearchTableModel model = (SearchTableModel)table.ge tModel();
SearchTableObject obj =
(SearchTableObject)model.g etTableObj ect (selectedRow);
obj.setField1("Changed");
obj.setField2("Changed too");
obj.setField3("Also changed...");
model.fireTableRowsUpdated (selectedR ow, selectedRow); // needed
}
THis code is in the main Search page for the action on a popmenu on the jtable
if(e.getActionCommand() == "Update"){
if(selIndex == 0){
UpdateBook updateBook = new UpdateBook
(this.theDesktop,this.user , this.con,
rowRecBk[selectedRow][0], table,selectedRow);
updateBook.show();
}
}
This is in the update:
Constructor:
public UpdateBook(JComponent comp, String user, Connection con, String bookId, JTable table, int selectedRow){
super("Update Book", false, true, false, true);
this.con = con;
this.user = user;
this.comp = comp;
this.table = table;
this.selectedRow = selectedRow;
comp.add(this);
SetUpComponents();
GetBookDetails(bookId);
}
THis is when the Details have been updated:
JOptionPane.showMessageDia
selectedRow = table.getSelectedRow();
JOptionPane.showMessageDia
if (selectedRow!=-1) {
SearchTableModel model = (SearchTableModel)table.ge
SearchTableObject obj =
(SearchTableObject)model.g
obj.setField1("Changed");
obj.setField2("Changed too");
obj.setField3("Also changed...");
model.fireTableRowsUpdated
}
THis code is in the main Search page for the action on a popmenu on the jtable
if(e.getActionCommand() == "Update"){
if(selIndex == 0){
UpdateBook updateBook = new UpdateBook
(this.theDesktop,this.user
rowRecBk[selectedRow][0], table,selectedRow);
updateBook.show();
}
}
Just a remark:
Replace
>> if(e.getActionCommand() == "Update"){
by
if(e.getActionCommand().eq uals("Upda te")) {
That's safer.
Run this snippet and see why:
// Don't compare Strings by using ==
// Use equals() instead
StringBuffer buf1 = new StringBuffer("Hello");
StringBuffer buf2 = new StringBuffer("Hello");
String myStr1 = buf1.toString();
String myStr2 = buf2.toString();
if (myStr1 == myStr2)
System.out.println("1) equal");
else
System.out.println("1) not equal");
if (myStr1.equals(myStr2))
System.out.println("2) equal");
else
System.out.println("2) not equal");
Replace
>> if(e.getActionCommand() == "Update"){
by
if(e.getActionCommand().eq
That's safer.
Run this snippet and see why:
// Don't compare Strings by using ==
// Use equals() instead
StringBuffer buf1 = new StringBuffer("Hello");
StringBuffer buf2 = new StringBuffer("Hello");
String myStr1 = buf1.toString();
String myStr2 = buf2.toString();
if (myStr1 == myStr2)
System.out.println("1) equal");
else
System.out.println("1) not equal");
if (myStr1.equals(myStr2))
System.out.println("2) equal");
else
System.out.println("2) not equal");
>>THis code is in the main Search page for the action on a popmenu on the jtable
>> if(e.getActionCommand() == "Update"){
>> if(selIndex == 0){
>> UpdateBook updateBook = new UpdateBook
>> (this.theDesktop,this.user , this.con,
>> rowRecBk[selectedRow][0], table,selectedRow); // <<<<<<<<<<
>>
>> updateBook.show();
>>
>> }
>> }
Is "selectedRow" OK (I mean !=-1) at the marked line of code?
How is it determined? As table.getSelectedRow()?
Than table.getSelectedRow() should be !=-1 inside the function too.
>>THis is when the Details have been updated:
>>JOptionPane.showMessageD ialog(this , "Book has been updated successfully");
>>selectedRow = table.getSelectedRow();
Is this code part of the Search window code or the update window code?
You should be aware of the fact that the selection is gone if you reset the table's model.
>> if(e.getActionCommand() == "Update"){
>> if(selIndex == 0){
>> UpdateBook updateBook = new UpdateBook
>> (this.theDesktop,this.user
>> rowRecBk[selectedRow][0], table,selectedRow); // <<<<<<<<<<
>>
>> updateBook.show();
>>
>> }
>> }
Is "selectedRow" OK (I mean !=-1) at the marked line of code?
How is it determined? As table.getSelectedRow()?
Than table.getSelectedRow() should be !=-1 inside the function too.
>>THis is when the Details have been updated:
>>JOptionPane.showMessageD
>>selectedRow = table.getSelectedRow();
Is this code part of the Search window code or the update window code?
You should be aware of the fact that the selection is gone if you reset the table's model.
ASKER
>Is "selectedRow" OK (I mean !=-1) at the marked line of code?this is the code ?
it is 1 at this point
in the main search page that I use to get the selectedRow
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionList ener(new ListSelectionListener(){
public void valueChanged(ListSelection Event e) {
ListSelectionModel lsm = (ListSelectionModel)e.getS ource();
if (!lsm.isSelectionEmpty()) {
selectedRow = lsm.getMinSelectionIndex() ;
}
}
});
>>THis is when the Details have been updated:
>>JOptionPane.showMessageD ialog(this , "Book has been updated successfully");
>>selectedRow = table.getSelectedRow();
This is part of the update window code.
it is 1 at this point
in the main search page that I use to get the selectedRow
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionList
public void valueChanged(ListSelection
ListSelectionModel lsm = (ListSelectionModel)e.getS
if (!lsm.isSelectionEmpty()) {
selectedRow = lsm.getMinSelectionIndex()
}
}
});
>>THis is when the Details have been updated:
>>JOptionPane.showMessageD
>>selectedRow = table.getSelectedRow();
This is part of the update window code.
>> it is 1 at this point
Then table.getSelectedRow() should be 1 inside the update window code too.
>>THis is when the Details have been updated
Why do you need the selected row *after* the details have been updated?
I would say you need the selected row to determine which item to update...
Then table.getSelectedRow() should be 1 inside the update window code too.
>>THis is when the Details have been updated
Why do you need the selected row *after* the details have been updated?
I would say you need the selected row to determine which item to update...
ASKER
>>Then table.getSelectedRow() should be 1 inside the update window code too.
Yes, but for some reason it's -1 and I did a message box for both and they were different.
This is the constructor for the update window.
UpdateBook(JComponent comp, String user, Connection con, String bookId, JTable table, int selectedRow)
I use the bookId to bring up all the book details and then I can change them.
So when I hit the update button on the update window it updates the database.
I then get the rowSelected again to update the JTable in the Search window.
Does this make sense to you?
Yes, but for some reason it's -1 and I did a message box for both and they were different.
This is the constructor for the update window.
UpdateBook(JComponent comp, String user, Connection con, String bookId, JTable table, int selectedRow)
I use the bookId to bring up all the book details and then I can change them.
So when I hit the update button on the update window it updates the database.
I then get the rowSelected again to update the JTable in the Search window.
Does this make sense to you?
>> Yes, but for some reason it's -1
Impossible.
Try this in the constructor:
public UpdateBook(JComponent comp, String user, Connection con, String bookId, JTable table, int selectedRow){
super("Update Book", false, true, false, true);
this.con = con;
this.user = user;
this.comp = comp;
this.table = table;
System.out.println("a) Selected row: " + table.getSelectedRow()); // <<<<<<<<<<<<
this.selectedRow = selectedRow;
System.out.println("b) Selected row: " + selectedRow); // <<<<<<<<<<<<
comp.add(this);
SetUpComponents();
GetBookDetails(bookId);
}
It should print 1 twice. (I'm rather sure it will)
>> So when I hit the update button on the update window it updates the database.
>> I then get the rowSelected again to update the JTable in the Search window
>> Does this make sense to you?
Yes. At first sight.
Impossible.
Try this in the constructor:
public UpdateBook(JComponent comp, String user, Connection con, String bookId, JTable table, int selectedRow){
super("Update Book", false, true, false, true);
this.con = con;
this.user = user;
this.comp = comp;
this.table = table;
System.out.println("a) Selected row: " + table.getSelectedRow()); // <<<<<<<<<<<<
this.selectedRow = selectedRow;
System.out.println("b) Selected row: " + selectedRow); // <<<<<<<<<<<<
comp.add(this);
SetUpComponents();
GetBookDetails(bookId);
}
It should print 1 twice. (I'm rather sure it will)
>> So when I hit the update button on the update window it updates the database.
>> I then get the rowSelected again to update the JTable in the Search window
>> Does this make sense to you?
Yes. At first sight.
ASKER
I'll try that so.
But I put a check for the selected row in the Search window just before I pass the
table in and it comes up as -1 there!
That doesnt make sense!
But I put a check for the selected row in the Search window just before I pass the
table in and it comes up as -1 there!
That doesnt make sense!
ASKER
I got the following results:
a) Selected row: -1
b) Selected row: 1
a) Selected row: -1
b) Selected row: 1
Which seems to indicate that you pass the wrong JTable object.
Another test. Could you add this:
THis code is in the main Search page for the action on a popmenu on the jtable
if(e.getActionCommand() == "Update"){
if(selIndex == 0){
System.out.println("c) Selected row = " + table.getSelectedRow()); // <<<<<<<<<<
UpdateBook updateBook = new UpdateBook
(this.theDesktop,this.user , this.con,
rowRecBk[selectedRow][0], table,selectedRow);
updateBook.show();
}
}
I expect it to be -1 too.
Which means that the selection is already "gone" (?), when reaching this instruction.
Then simply use the passed selectedRow in your update window.
Can you explain what
>> if(selIndex == 0){
is for in the above code?
Another test. Could you add this:
THis code is in the main Search page for the action on a popmenu on the jtable
if(e.getActionCommand() == "Update"){
if(selIndex == 0){
System.out.println("c) Selected row = " + table.getSelectedRow()); // <<<<<<<<<<
UpdateBook updateBook = new UpdateBook
(this.theDesktop,this.user
rowRecBk[selectedRow][0], table,selectedRow);
updateBook.show();
}
}
I expect it to be -1 too.
Which means that the selection is already "gone" (?), when reaching this instruction.
Then simply use the passed selectedRow in your update window.
Can you explain what
>> if(selIndex == 0){
is for in the above code?
ASKER
This is the code I wrote to make the JTable:
private void makeTable (String[][] rowRec) {
//String Array For Table Columns.
String colsName[] = {"Book No" ,"Book ISBN", "Book Title", "Book
Author", "Category", "Member ID", "Status"};
int j = 0;
List data = new ArrayList();
for(int i=0; i < rowRec.length; i++){
System.out.println("length of rowRec" + rowRec.length);
data.add( new SearchTableObject(rowRec[i ][j], rowRec[i][++j],
rowRec[i][++j], rowRec[i][++j], rowRec[i][++j],
rowRec[i][++j], rowRec[i][++j] ));
j = 0;
}
table = new JTable ();
table.setModel(new SearchTableModel(data, colsName));
table.getModel().addTableM odelListen er(this);
int s = table.getSelectedRow();
System.out.println("In make table selected Row = " + s);
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionList ener(new ListSelectionListener(){
public void valueChanged(ListSelection Event e) {
ListSelectionModel lsm = (ListSelectionModel)e.getS ource();
if (!lsm.isSelectionEmpty()) {
selectedRow = lsm.getMinSelectionIndex() ;
}
}
});
if(table.getModel().getRow Count() > 0)
//rowSM.setSelectionInterv al(0,0);
table.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
int nModifier = e.getModifiers();
JTable table = (JTable)e.getSource();
int selectedRow = table.rowAtPoint(e.getPoin t());
constructPopupMenu();
popupmenu.show(table,e.get X(), e.getY());
}
});
//Remove the ID column from the table
TableColumnModel columnNo = table.getColumnModel();
columnNo.removeColumn( columnNo.getColumn( 0 ) );
}
private void makeTable (String[][] rowRec) {
//String Array For Table Columns.
String colsName[] = {"Book No" ,"Book ISBN", "Book Title", "Book
Author", "Category", "Member ID", "Status"};
int j = 0;
List data = new ArrayList();
for(int i=0; i < rowRec.length; i++){
System.out.println("length
data.add( new SearchTableObject(rowRec[i
rowRec[i][++j], rowRec[i][++j], rowRec[i][++j],
rowRec[i][++j], rowRec[i][++j] ));
j = 0;
}
table = new JTable ();
table.setModel(new SearchTableModel(data, colsName));
table.getModel().addTableM
int s = table.getSelectedRow();
System.out.println("In make table selected Row = " + s);
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionList
public void valueChanged(ListSelection
ListSelectionModel lsm = (ListSelectionModel)e.getS
if (!lsm.isSelectionEmpty()) {
selectedRow = lsm.getMinSelectionIndex()
}
}
});
if(table.getModel().getRow
//rowSM.setSelectionInterv
table.addMouseListener(new
public void mousePressed(MouseEvent e){
int nModifier = e.getModifiers();
JTable table = (JTable)e.getSource();
int selectedRow = table.rowAtPoint(e.getPoin
constructPopupMenu();
popupmenu.show(table,e.get
}
});
//Remove the ID column from the table
TableColumnModel columnNo = table.getColumnModel();
columnNo.removeColumn( columnNo.getColumn( 0 ) );
}
ASKER
>> if(selIndex == 0){
I have a tabbed pane, and I just am checking here if the tab seleceted is tab 0
also above table is defined as
private JTable table;
in the Search class
I have a tabbed pane, and I just am checking here if the tab seleceted is tab 0
also above table is defined as
private JTable table;
in the Search class
ASKER
I tried using the selected row passed in and I got this error:
java.lang.IndexOutOfBounds Exception: Index: 1, Size: 1
at java.util.ArrayList.RangeC heck(Unkno wn Source)
at java.util.ArrayList.get(Un known Source)
at Logon.SearchTableModel.get TableObjec t(SearchTa bleModel.j ava:20)
at Logon.UpdateBook.UpdateBoo k(UpdateBo ok.java:38 0)
at Logon.UpdateBook.actionPer formed(Upd ateBook.ja va:278)
at javax.swing.AbstractButton .fireActio nPerformed (Unknown Source)
at javax.swing.AbstractButton $ForwardAc tionEvents .actionPer formed(Unk nown Source)
at javax.swing.DefaultButtonM odel.fireA ctionPerfo rmed(Unkno wn Source)
at javax.swing.DefaultButtonM odel.setPr essed(Unkn own Source)
at javax.swing.plaf.basic.Bas icButtonLi stener.mou seReleased (Unknown Source)
at java.awt.Component.process MouseEvent (Unknown Source)
at java.awt.Component.process Event(Unkn own Source)
at java.awt.Container.process Event(Unkn own Source)
at java.awt.Component.dispatc hEventImpl (Unknown Source)
at java.awt.Container.dispatc hEventImpl (Unknown Source)
at java.awt.Component.dispatc hEvent(Unk nown Source)
at java.awt.LightweightDispat cher.retar getMouseEv ent(Unknow n Source)
at java.awt.LightweightDispat cher.proce ssMouseEve nt(Unknown Source)
at java.awt.LightweightDispat cher.dispa tchEvent(U nknown Source)
at java.awt.Container.dispatc hEventImpl (Unknown Source)
at java.awt.Window.dispatchEv entImpl(Un known Source)
at java.awt.Component.dispatc hEvent(Unk nown Source)
at java.awt.EventQueue.dispat chEvent(Un known Source)
at java.awt.EventDispatchThre ad.pumpOne EventForHi erarchy(Un known Source)
at java.awt.EventDispatchThre ad.pumpEve ntsForHier archy(Unkn own Source)
at java.awt.EventDispatchThre ad.pumpEve nts(Unknow n Source)
at java.awt.EventDispatchThre ad.pumpEve nts(Unknow n Source)
at java.awt.EventDispatchThre ad.run(Unk nown Source)
java.lang.IndexOutOfBounds
at java.util.ArrayList.RangeC
at java.util.ArrayList.get(Un
at Logon.SearchTableModel.get
at Logon.UpdateBook.UpdateBoo
at Logon.UpdateBook.actionPer
at javax.swing.AbstractButton
at javax.swing.AbstractButton
at javax.swing.DefaultButtonM
at javax.swing.DefaultButtonM
at javax.swing.plaf.basic.Bas
at java.awt.Component.process
at java.awt.Component.process
at java.awt.Container.process
at java.awt.Component.dispatc
at java.awt.Container.dispatc
at java.awt.Component.dispatc
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.Container.dispatc
at java.awt.Window.dispatchEv
at java.awt.Component.dispatc
at java.awt.EventQueue.dispat
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
>>I tried using the selected row passed in and I got this error:
>>java.lang.IndexOutOfBoun dsExceptio n: Index: 1, Size: 1
>>at java.util.ArrayList.RangeC heck(Unkno wn Source)
>>at java.util.ArrayList.get(Un known Source)
>>at Logon.SearchTableModel.get TableObjec t(SearchTa bleModel.j ava:20)
Which means that you try to perform getTableObject(1) on your SearchTableModel,
while it only contains one item. So 1 is an invalid index.
Hey,
>> int selectedRow = table.rowAtPoint(e.getPoin t());
this is no good!
It's not because you right-click on a table item that it is also selected, is it?
So, selectedRow will become 1 or whatever the index of the corresponding row might be,
(that's the index of the row you right-clicked on) while table.getSelectedRow() remains -1 (no row selected)
That's why we had the previous problems.
>>java.lang.IndexOutOfBoun
>>at java.util.ArrayList.RangeC
>>at java.util.ArrayList.get(Un
>>at Logon.SearchTableModel.get
Which means that you try to perform getTableObject(1) on your SearchTableModel,
while it only contains one item. So 1 is an invalid index.
Hey,
>> int selectedRow = table.rowAtPoint(e.getPoin
this is no good!
It's not because you right-click on a table item that it is also selected, is it?
So, selectedRow will become 1 or whatever the index of the corresponding row might be,
(that's the index of the row you right-clicked on) while table.getSelectedRow() remains -1 (no row selected)
That's why we had the previous problems.
btw, I'm almost reaching my 50 points-limit ;°)
ASKER
I tried to do this in the constructor of SearchTableModel:
public SearchTableModel(List d, String[] columnNames) {
this.data = d;
this.columnNames = columnNames;
System.out.println("length of data = " + d.getItemCount());
}
I get the following compiler error:
SearchTableModel.java:19: cannot resolve symbol
symbol : method getItemCount ()
location: interface java.util.List
System.out.println("length of data = " + d.getItemCount());
^
public SearchTableModel(List d, String[] columnNames) {
this.data = d;
this.columnNames = columnNames;
System.out.println("length
}
I get the following compiler error:
SearchTableModel.java:19: cannot resolve symbol
symbol : method getItemCount ()
location: interface java.util.List
System.out.println("length
^
ASKER
Ok can Increase the points, would that be ok?
getItemCount() doesn't exist on List. Use size().
This error means that the code you gave before
>> table.setModel(new SearchTableModel(data, colsName));
has never run.
Then you make it rather difficult for me to help you.
Please be honest.
This error means that the code you gave before
>> table.setModel(new SearchTableModel(data, colsName));
has never run.
Then you make it rather difficult for me to help you.
Please be honest.
ASKER
What do you mean by please be honest?
I used size above and got back 1 so there is something in the data is there not?
I used size above and got back 1 so there is something in the data is there not?
ASKER
I found some of the problem!
I have two tabs and I use the same function to make the JTable.
So the second tab overwrites the data of the first.
I'll have to find a way round this.
I have two tabs and I use the same function to make the JTable.
So the second tab overwrites the data of the first.
I'll have to find a way round this.
>>What do you mean by please be honest?
I mean: Don't post code you don't run.
But my sincere apologies, I see I misinterpreted.
You just (try to) add
>> System.out.println("length of data = " + d.getItemCount());
in the SearchTableModel.
OK.
>> I used size above and got back 1 so there is something in the data is there not?
Yes, there is something in, but that means that there is only one record in.
That's why trying to get the table object on the 2nd row gives an exception.
So, selectedRow shouldn't be 1, but 0.
Up to you to find out why it is 1 instead of 0.
I mean: Don't post code you don't run.
But my sincere apologies, I see I misinterpreted.
You just (try to) add
>> System.out.println("length
in the SearchTableModel.
OK.
>> I used size above and got back 1 so there is something in the data is there not?
Yes, there is something in, but that means that there is only one record in.
That's why trying to get the table object on the 2nd row gives an exception.
So, selectedRow shouldn't be 1, but 0.
Up to you to find out why it is 1 instead of 0.
>> So the second tab overwrites the data of the first.
Whooo. Nasty ;°)
>> I use the same function to make the JTable.
Do you want the table's in both tabs to contain the same data?
No? Then why use the same JTable/table model?
Whooo. Nasty ;°)
>> I use the same function to make the JTable.
Do you want the table's in both tabs to contain the same data?
No? Then why use the same JTable/table model?
>> I use the same function to make the JTable.
Which one?
Which one?
ASKER
>>Which one?
private void makeTable (String[][] rowRec) that I posted above.
Ok all that works fine now.
What was happening was that I have a JTabbedPane with two tabs
and I use the same makeTable function to display up results.
I send in different 2-d arrays depending on the tab that is currently
selected.
Should I have 2 different functions to create the table for each tab?
private void makeTable (String[][] rowRec) that I posted above.
Ok all that works fine now.
What was happening was that I have a JTabbedPane with two tabs
and I use the same makeTable function to display up results.
I send in different 2-d arrays depending on the tab that is currently
selected.
Should I have 2 different functions to create the table for each tab?
ASKER
or I could have two Lists in the SearchTableModel class
one for each tab?
one for each tab?
>> Should I have 2 different functions to create the table for each tab?
>> or I could have two Lists in the SearchTableModel class
>> one for each tab?
No, you should just use two different SearchTableModel instances; one for each JTable.
For the first JTable you pass the first data list.
For the 2nd JTable you pass another data list.
>> or I could have two Lists in the SearchTableModel class
>> one for each tab?
No, you should just use two different SearchTableModel instances; one for each JTable.
For the first JTable you pass the first data list.
For the 2nd JTable you pass another data list.
List data1 = new ArrayList();
// create your data for the 1st table
table = new JTable ();
table.setModel(new SearchTableModel(data1, colsName));
List data2 = new ArrayList();
// create your data for the 2nd table
table2 = new JTable ();
table2.setModel(new SearchTableModel(data2, colsName));
// create your data for the 1st table
table = new JTable ();
table.setModel(new SearchTableModel(data1, colsName));
List data2 = new ArrayList();
// create your data for the 2nd table
table2 = new JTable ();
table2.setModel(new SearchTableModel(data2, colsName));
ASKER
Hi,
I got the above sorted anyway. But a few strange things seem to be happening.
When I update the details in the update I printed the following to the console:
Before update
Field2 = 0-672-32128-9
Field3 = title1
Field4 = author1
Field5 = Java
after update: (this is what is displayed in the table)
Field3 changed = author2 (field3 should be title2)
Field4 changed = author1 (field4 should be author2)
I got the above sorted anyway. But a few strange things seem to be happening.
When I update the details in the update I printed the following to the console:
Before update
Field2 = 0-672-32128-9
Field3 = title1
Field4 = author1
Field5 = Java
after update: (this is what is displayed in the table)
Field3 changed = author2 (field3 should be title2)
Field4 changed = author1 (field4 should be author2)
ASKER
I thought that since I removed a column in the maketable function code
above that it might cause problems but it should'nt should it?
above that it might cause problems but it should'nt should it?
ASKER
I put back the column I removed and tried that but it still gave me the same
problem!
problem!
ASKER
actually it only seems to set the first 3 columns? any idea?
>> actually it only seems to set the first 3 columns? any idea?
Can you post the table model you use at the moment?
Can you post the table model you use at the moment?
ASKER
This is the table model, nearly same as the one you posted earlier
package Logon;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.util.List;
public class SearchTableModel extends DefaultTableModel {
List data; // a list of MyObject's
private String[] columnNames;
/** Creates a new instance of MyTableModel */
public SearchTableModel(List d, String[] columnNames) {
this.data = d;
this.columnNames = columnNames;
System.out.println("length of data = " + data.size());
}
public Object getTableObject(int index) {
return data.get(index);
}
public void setColumnName(int index, String name) {
if (index < columnNames.length)
columnNames[index] = name;
}
public boolean isCellEditable(int row, int col) {
return false;
}
public void addRow(SearchTableObject object) {
data.add(object);
fireTableRowsInserted(data .size()-2, data.size()-2);
}
public void removeRow(int index) {
data.remove(index);
fireTableRowsDeleted(index , index);
}
public Class getColumnClass(int col) {
return super.getColumnClass(col);
}
public int getRowCount() {
return data==null ? 0 : data.size();
}
public int getColumnCount() {
return columnNames.length;
}
public Object getValueAt(int row, int col) {
if ( row < 0 || row >= data.size() ) return null;
SearchTableObject myObj = (SearchTableObject) data.get(row);
if (col==0)
return myObj.getField1();
else if (col==1)
return myObj.getField2();
else if (col==2)
return myObj.getField3();
else if (col==3)
return myObj.getField4();
else if (col==4)
return myObj.getField5();
else if (col==5)
return myObj.getField6();
else if (col==6)
return myObj.getField7();
else return null;
}
// not needed if not editable:
public void setValueAt(Object value, int row, int col) {
if ( row < 0 || row >= data.size() /*|| col!=0*/ ) return;
// only col=0 is editable (in this example)
SearchTableObject myObj = (SearchTableObject) data.get(row);
if (col==0)
myObj.setField1( (String)value );
else if (col==1)
myObj.setField2( (String)value );
else if (col==2)
myObj.setField3( (String)value );
else if (col==3)
myObj.setField4( (String)value );
else if (col==4)
myObj.setField5( (String)value );
else if (col==5)
myObj.setField6( (String)value );
else if (col==6)
myObj.setField7( (String)value );
fireTableCellUpdated(row, col);
}
public String getColumnName(int col) {
return columnNames[col];
}
}
package Logon;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.util.List;
public class SearchTableModel extends DefaultTableModel {
List data; // a list of MyObject's
private String[] columnNames;
/** Creates a new instance of MyTableModel */
public SearchTableModel(List d, String[] columnNames) {
this.data = d;
this.columnNames = columnNames;
System.out.println("length
}
public Object getTableObject(int index) {
return data.get(index);
}
public void setColumnName(int index, String name) {
if (index < columnNames.length)
columnNames[index] = name;
}
public boolean isCellEditable(int row, int col) {
return false;
}
public void addRow(SearchTableObject object) {
data.add(object);
fireTableRowsInserted(data
}
public void removeRow(int index) {
data.remove(index);
fireTableRowsDeleted(index
}
public Class getColumnClass(int col) {
return super.getColumnClass(col);
}
public int getRowCount() {
return data==null ? 0 : data.size();
}
public int getColumnCount() {
return columnNames.length;
}
public Object getValueAt(int row, int col) {
if ( row < 0 || row >= data.size() ) return null;
SearchTableObject myObj = (SearchTableObject) data.get(row);
if (col==0)
return myObj.getField1();
else if (col==1)
return myObj.getField2();
else if (col==2)
return myObj.getField3();
else if (col==3)
return myObj.getField4();
else if (col==4)
return myObj.getField5();
else if (col==5)
return myObj.getField6();
else if (col==6)
return myObj.getField7();
else return null;
}
// not needed if not editable:
public void setValueAt(Object value, int row, int col) {
if ( row < 0 || row >= data.size() /*|| col!=0*/ ) return;
// only col=0 is editable (in this example)
SearchTableObject myObj = (SearchTableObject) data.get(row);
if (col==0)
myObj.setField1( (String)value );
else if (col==1)
myObj.setField2( (String)value );
else if (col==2)
myObj.setField3( (String)value );
else if (col==3)
myObj.setField4( (String)value );
else if (col==4)
myObj.setField5( (String)value );
else if (col==5)
myObj.setField6( (String)value );
else if (col==6)
myObj.setField7( (String)value );
fireTableCellUpdated(row, col);
}
public String getColumnName(int col) {
return columnNames[col];
}
}
ASKER
I've tried absolutely nearly eveything to sort out the above
problem.
Field1, Field2, Field3 update fine from the update window
to the table on the Search window. If I change Field4
Field 3 is overwritten with what Field4 is set to etc
So if Field 4,5,6 are changed Field3 in the table is overwritten by first field4 value then Field5 value then Field6 value.
Cant see what the problem is????
Would you have any ideas?
problem.
Field1, Field2, Field3 update fine from the update window
to the table on the Search window. If I change Field4
Field 3 is overwritten with what Field4 is set to etc
So if Field 4,5,6 are changed Field3 in the table is overwritten by first field4 value then Field5 value then Field6 value.
Cant see what the problem is????
Would you have any ideas?
ASKER
Maybe you want me to increase the points?
Sorry, I really have no idea.
I would check (by printing out)
- if you really change the fields you think you change
- if you really show the fields you think you show in that column
I would check (by printing out)
- if you really change the fields you think you change
- if you really show the fields you think you show in that column
ASKER
I've tried all that.
I print out by using the getFieldX function before I change
them and they are print out exactly what is there.
Then I set the first 3 fields by using the setFieldX function and that is grand.
It is when I try to set field4 it goes in field3
and if I set field5 it goes into field3 and if I set field6 it goes into field3.
I know the orig. example you gave me above had just 3 fields in it did you set the no of fields anywhere to 3 maybe?
I print out by using the getFieldX function before I change
them and they are print out exactly what is there.
Then I set the first 3 fields by using the setFieldX function and that is grand.
It is when I try to set field4 it goes in field3
and if I set field5 it goes into field3 and if I set field6 it goes into field3.
I know the orig. example you gave me above had just 3 fields in it did you set the no of fields anywhere to 3 maybe?
>> I know the orig. example you gave me above had just 3 fields in it
I thought about that to, but your SearchTableModel is just OK.
>> It is when I try to set field4 it goes in field3
Did you check that *the object's field3* is really changed (data) or do you just *see* it in that table that way (view)?
Difficult to help without your code :°/
But I guess it is too much to post...
Maybe you can post where you perform the field changes?
I thought about that to, but your SearchTableModel is just OK.
>> It is when I try to set field4 it goes in field3
Did you check that *the object's field3* is really changed (data) or do you just *see* it in that table that way (view)?
Difficult to help without your code :°/
But I guess it is too much to post...
Maybe you can post where you perform the field changes?
ASKER
>>Maybe you can post where you perform the field >>changes?
This is where I make the changes.
obj.setField2(strTitle);
obj.setField3(strAuthor);
obj.setField4(
Category[1][cboCategory.ge tSelectedI ndex()] );
It's just that field4 is written into field3 on the view of the table.
I dont change the data at all would that make a difference?
Would I have to?
This is where I make the changes.
obj.setField2(strTitle);
obj.setField3(strAuthor);
obj.setField4(
Category[1][cboCategory.ge
It's just that field4 is written into field3 on the view of the table.
I dont change the data at all would that make a difference?
Would I have to?
>> It's just that field4 is written into field3 on the view of the table
So in reality that field3 still has its previous value and field4 is changed? Sure the object's setField4() is OK?
So it's a visualization problem?
What can I say?
It is impossible if you use this in the table model:
public Object getValueAt(int row, int col) {
if ( row < 0 || row >= data.size() ) return null;
SearchTableObject myObj = (SearchTableObject) data.get(row);
if (col==0)
return myObj.getField1();
else if (col==1)
return myObj.getField2();
else if (col==2) // 3rd column
return myObj.getField3(); // 3rd field
else if (col==3) // 4th column
return myObj.getField4(); // 4th field
else if (col==4)
return myObj.getField5();
else if (col==5)
return myObj.getField6();
else if (col==6)
return myObj.getField7();
else return null;
}
So in reality that field3 still has its previous value and field4 is changed? Sure the object's setField4() is OK?
So it's a visualization problem?
What can I say?
It is impossible if you use this in the table model:
public Object getValueAt(int row, int col) {
if ( row < 0 || row >= data.size() ) return null;
SearchTableObject myObj = (SearchTableObject) data.get(row);
if (col==0)
return myObj.getField1();
else if (col==1)
return myObj.getField2();
else if (col==2) // 3rd column
return myObj.getField3(); // 3rd field
else if (col==3) // 4th column
return myObj.getField4(); // 4th field
else if (col==4)
return myObj.getField5();
else if (col==5)
return myObj.getField6();
else if (col==6)
return myObj.getField7();
else return null;
}
ASKER
I'll try writing up some code that could run on it's own
and I'll post it tomorrow.
Thanks for all your help, very much appreciated.
V
and I'll post it tomorrow.
Thanks for all your help, very much appreciated.
V
OK
CU
CU
ASKER
Hi,
I've wrote some independant code that is doing similar to what is happening here, if you have the
time to take a look that would be great, thanks.
What's happening in this one is that the last column is not being updated, it updates the secondlast column
with the last columns data.
//TableDemo.java
package Logon;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.util.List;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author zzynx
*/
public class TableDemo extends javax.swing.JFrame implements ActionListener{
/** Creates new form TableDemo */
public TableDemo() {
initComponents();
}
private void initTable() {
int j = 0;
for(int i=0; i < rowRec.length; i++){
data.add(new SearchTableObject(rowRec[i ][j++], rowRec[i][j++], rowRec[i][j++], rowRec[i][j++], rowRec[i][j++], rowRec[i][j++]));
j = 0;
}
table.setModel(new SearchTableModel(data, colsName));
}
private JTable makeTable () {
table = new JTable ();
initTable();
table.setModel(new SearchTableModel(data, colsName));
table.getModel().addTableM odelListen er(table);
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionList ener(new ListSelectionListener(){
public void valueChanged(ListSelection Event e) {
ListSelectionModel lsm = (ListSelectionModel)e.getS ource();
if (!lsm.isSelectionEmpty()) {
selectedRow = lsm.getMinSelectionIndex() ;
}
}
});
if(table.getModel().getRow Count() > 0)
table.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
int nModifier = e.getModifiers();
JTable table = (JTable)e.getSource();
int selectedRow = table.rowAtPoint(e.getPoin t());
constructPopupMenu(table);
popupmenu.show(table,e.get X(), e.getY());
}
});
return table;
}
private void constructPopupMenu(JTable table){
popupmenu = new JPopupMenu();
// Create some menu items for the popup
JMenuItem menuIssue = new JMenuItem( "Issue" );
JMenuItem menuReturn = new JMenuItem( "Return" );
JMenuItem menuDelete = new JMenuItem( "Delete" );
JMenuItem menuUpdate = new JMenuItem( "Update" );
JMenuItem menuDetails = new JMenuItem( "Details" );
// Create a popup menu
popupmenu = new JPopupMenu( "Menu" );
popupmenu.add( menuIssue );
popupmenu.add( menuReturn );
popupmenu.add( menuDelete );
popupmenu.add( menuUpdate );
popupmenu.add( menuDetails );
// Action and mouse listener support
enableEvents( AWTEvent.MOUSE_EVENT_MASK );
menuIssue.addActionListene r( this );
menuReturn.addActionListen er( this );
menuDelete.addActionListen er( this );
menuUpdate.addActionListen er( this );
menuDetails.addActionListe ner( this );
SearchTableModel model = (SearchTableModel)table.ge tModel();
SearchTableObject obj = (SearchTableObject)model.g etTableObj ect(select edRow);
if(obj.getField6().equals( "Reserved" )){
menuIssue.setEnabled(false );
}else if(obj.getField6().equals( "Available ")){
menuReturn.setEnabled(fals e);
}
}
public void actionPerformed(ActionEven t e){
if(e.getActionCommand() == "Update"){
UpdateBook updateBK = new UpdateBook(theDesktop, rowRec[selectedRow][0], table, selectedRow);
updateBK.show();
}
}
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
theTable = makeTable();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
addButton = new javax.swing.JButton();
deleteButton = new javax.swing.JButton();
changeButton = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapt er() {
public void windowClosing(java.awt.eve nt.WindowE vent evt) {
exitForm(evt);
}
});
jScrollPane1.setViewportVi ew(theTabl e);
getContentPane().add(jScro llPane1, java.awt.BorderLayout.CENT ER);
jPanel1.setLayout(new java.awt.FlowLayout(java.a wt.FlowLay out.RIGHT) );
addButton.setText("Add");
addButton.addActionListene r(new java.awt.event.ActionListe ner() {
public void actionPerformed(java.awt.e vent.Actio nEvent evt) {
addButtonActionPerformed(e vt);
}
});
jPanel2.add(addButton);
deleteButton.setText("Dele te");
deleteButton.addActionList ener(new java.awt.event.ActionListe ner() {
public void actionPerformed(java.awt.e vent.Actio nEvent evt) {
deleteButtonActionPerforme d(evt);
}
});
jPanel2.add(deleteButton);
changeButton.setText("Chan ge");
changeButton.addActionList ener(new java.awt.event.ActionListe ner() {
public void actionPerformed(java.awt.e vent.Actio nEvent evt) {
changeButtonActionPerforme d(evt);
}
});
jPanel2.add(changeButton);
jPanel1.add(jPanel2);
//getContentPane().add(the Desktop);
getContentPane().add(jPane l1, java.awt.BorderLayout.SOUT H);
pack();
}
private void changeButtonActionPerforme d(java.awt .event.Act ionEvent evt) {
int selectedRow = theTable.getSelectedRow();
if (selectedRow!=-1) {
SearchTableModel model = (SearchTableModel)theTable .getModel( );
SearchTableObject obj = (SearchTableObject)model.g etTableObj ect(select edRow);
obj.setField1("Changed");
obj.setField2("Changed too");
obj.setField3("Also changed...");
obj.setField4("New one1...");
obj.setField5("New one2...");
obj.setField6("New one3...");
model.fireTableRowsUpdated (selectedR ow, selectedRow); // needed
}
}
private void deleteButtonActionPerforme d(java.awt .event.Act ionEvent evt) {
if (theTable.getSelectedRow() !=-1)
((SearchTableModel)theTabl e.getModel ()).remove Row(
theTable.getSelectedRow() );
}
private void addButtonActionPerformed(j ava.awt.ev ent.Action Event evt) {
((SearchTableModel)theTabl e.getModel ()).addRow (
new SearchTableObject("aaaaa", "bbbbbb", "ccccc", "dddd", "eeee", "ffff" ) );
}
/** Exit the Application */
private void exitForm(java.awt.event.Wi ndowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
UIManager.setLookAndFeel(U IManager.g etSystemLo okAndFeelC lassName() );
}
catch (Exception e) {
System.exit(0);
}
new TableDemo().show();
}
// Variables declaration - do not modify
private javax.swing.JButton addButton;
private javax.swing.JButton changeButton;
private javax.swing.JButton deleteButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable theTable;
private List data = new ArrayList();
private int selectedRow;
private JPopupMenu popupmenu;
private JTable table;
private String colsName[] = {"RefNo", "Title", "Author", "Category", "Member ID", "Status"};
private JDesktopPane theDesktop = new JDesktopPane ();
private String[][] rowRec = {
{"1234", "Java", "JB", "Java", "vbourke", "available"},
{"5678", "Java2", "VB", "Java", "vblogs1", "available"},
{"0112", "Java3", "SB", "Java", "vblogs2", "available"},
{"3456", "Java4", "DB", "Java", "vblogs3", "available"},
{"7892", "Java5", "NB", "Java", "vblogs4", "available"},
};
// End of variables declaration
}
//SearchTableModel.java
package Logon;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.util.List;
public class SearchTableModel extends DefaultTableModel {
List data; // a list of MyObject's
private String[] columnNames;
/** Creates a new instance of MyTableModel */
public SearchTableModel(List d, String[] columnNames) {
this.data = d;
this.columnNames = columnNames;
System.out.println("length of data = " + data.size());
}
public Object getTableObject(int index) {
return data.get(index);
}
public void setColumnName(int index, String name) {
if (index < columnNames.length)
columnNames[index] = name;
}
public boolean isCellEditable(int row, int col) {
return false;
}
public void addRow(SearchTableObject object) {
data.add(object);
fireTableRowsInserted(data .size()-2, data.size()-2);
}
public void removeRow(int index) {
data.remove(index);
fireTableRowsDeleted(index , index);
}
public Class getColumnClass(int col) {
return super.getColumnClass(col);
}
public int getRowCount() {
return data==null ? 0 : data.size();
}
public int getColumnCount() {
return columnNames.length;
}
public Object getValueAt(int row, int col) {
if ( row < 0 || row >= data.size() ) return null;
SearchTableObject myObj = (SearchTableObject) data.get(row);
if (col==0)
return myObj.getField1();
else if (col==1)
return myObj.getField2();
else if (col==2)
return myObj.getField3();
else if (col==3)
return myObj.getField4();
else if (col==4)
return myObj.getField5();
else if (col==5)
return myObj.getField6();
else return null;
}
// not needed if not editable:
public void setValueAt(Object value, int row, int col) {
if ( row < 0 || row >= data.size() )/*|| col!=0 )*/ return;
// only col=0 is editable (in this example)
SearchTableObject myObj = (SearchTableObject) data.get(row);
if (col==0)
myObj.setField1( (String)value );
else if (col==1)
myObj.setField2( (String)value );
else if (col==2)
myObj.setField3( (String)value );
else if (col==3)
myObj.setField4( (String)value );
else if (col==4)
myObj.setField5( (String)value );
else if (col==5)
myObj.setField6( (String)value );
fireTableCellUpdated(row, col);
}
public String getColumnName(int col) {
return columnNames[col];
}
}
//SearchTableObject.java
package Logon;
public class SearchTableObject {
private String field1 = "";
private String field2 = "";
private String field3 = "";
private String field4 = "";
private String field5 = "";
private String field6 = "";
/** Creates a new instance of MyTableObject */
public SearchTableObject() {
}
public SearchTableObject(String f1, String f2, String f3, String f4, String f5, String f6) {
field1 = f1;
field2 = f2;
field3 = f3;
field4 = f4;
field5 = f5;
field6 = f6;
}
public String getField1() { return field1; }
public String getField2() { return field2; }
public String getField3() { return field3; }
public String getField4() { return field4; }
public String getField5() { return field5; }
public String getField6() { return field6; }
public void setField1(String f1) { field1 = f1; }
public void setField2(String f2) { field2 = f2; }
public void setField3(String f3) { field3 = f3; }
public void setField4(String f4) { field4 = f4; }
public void setField5(String f5) { field5 = f5; }
public void setField6(String f6) { field5 = f6; }
}
I've wrote some independant code that is doing similar to what is happening here, if you have the
time to take a look that would be great, thanks.
What's happening in this one is that the last column is not being updated, it updates the secondlast column
with the last columns data.
//TableDemo.java
package Logon;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.util.List;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author zzynx
*/
public class TableDemo extends javax.swing.JFrame implements ActionListener{
/** Creates new form TableDemo */
public TableDemo() {
initComponents();
}
private void initTable() {
int j = 0;
for(int i=0; i < rowRec.length; i++){
data.add(new SearchTableObject(rowRec[i
j = 0;
}
table.setModel(new SearchTableModel(data, colsName));
}
private JTable makeTable () {
table = new JTable ();
initTable();
table.setModel(new SearchTableModel(data, colsName));
table.getModel().addTableM
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionList
public void valueChanged(ListSelection
ListSelectionModel lsm = (ListSelectionModel)e.getS
if (!lsm.isSelectionEmpty()) {
selectedRow = lsm.getMinSelectionIndex()
}
}
});
if(table.getModel().getRow
table.addMouseListener(new
public void mousePressed(MouseEvent e){
int nModifier = e.getModifiers();
JTable table = (JTable)e.getSource();
int selectedRow = table.rowAtPoint(e.getPoin
constructPopupMenu(table);
popupmenu.show(table,e.get
}
});
return table;
}
private void constructPopupMenu(JTable table){
popupmenu = new JPopupMenu();
// Create some menu items for the popup
JMenuItem menuIssue = new JMenuItem( "Issue" );
JMenuItem menuReturn = new JMenuItem( "Return" );
JMenuItem menuDelete = new JMenuItem( "Delete" );
JMenuItem menuUpdate = new JMenuItem( "Update" );
JMenuItem menuDetails = new JMenuItem( "Details" );
// Create a popup menu
popupmenu = new JPopupMenu( "Menu" );
popupmenu.add( menuIssue );
popupmenu.add( menuReturn );
popupmenu.add( menuDelete );
popupmenu.add( menuUpdate );
popupmenu.add( menuDetails );
// Action and mouse listener support
enableEvents( AWTEvent.MOUSE_EVENT_MASK );
menuIssue.addActionListene
menuReturn.addActionListen
menuDelete.addActionListen
menuUpdate.addActionListen
menuDetails.addActionListe
SearchTableModel model = (SearchTableModel)table.ge
SearchTableObject obj = (SearchTableObject)model.g
if(obj.getField6().equals(
menuIssue.setEnabled(false
}else if(obj.getField6().equals(
menuReturn.setEnabled(fals
}
}
public void actionPerformed(ActionEven
if(e.getActionCommand() == "Update"){
UpdateBook updateBK = new UpdateBook(theDesktop, rowRec[selectedRow][0], table, selectedRow);
updateBK.show();
}
}
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
theTable = makeTable();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
addButton = new javax.swing.JButton();
deleteButton = new javax.swing.JButton();
changeButton = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapt
public void windowClosing(java.awt.eve
exitForm(evt);
}
});
jScrollPane1.setViewportVi
getContentPane().add(jScro
jPanel1.setLayout(new java.awt.FlowLayout(java.a
addButton.setText("Add");
addButton.addActionListene
public void actionPerformed(java.awt.e
addButtonActionPerformed(e
}
});
jPanel2.add(addButton);
deleteButton.setText("Dele
deleteButton.addActionList
public void actionPerformed(java.awt.e
deleteButtonActionPerforme
}
});
jPanel2.add(deleteButton);
changeButton.setText("Chan
changeButton.addActionList
public void actionPerformed(java.awt.e
changeButtonActionPerforme
}
});
jPanel2.add(changeButton);
jPanel1.add(jPanel2);
//getContentPane().add(the
getContentPane().add(jPane
pack();
}
private void changeButtonActionPerforme
int selectedRow = theTable.getSelectedRow();
if (selectedRow!=-1) {
SearchTableModel model = (SearchTableModel)theTable
SearchTableObject obj = (SearchTableObject)model.g
obj.setField1("Changed");
obj.setField2("Changed too");
obj.setField3("Also changed...");
obj.setField4("New one1...");
obj.setField5("New one2...");
obj.setField6("New one3...");
model.fireTableRowsUpdated
}
}
private void deleteButtonActionPerforme
if (theTable.getSelectedRow()
((SearchTableModel)theTabl
theTable.getSelectedRow() );
}
private void addButtonActionPerformed(j
((SearchTableModel)theTabl
new SearchTableObject("aaaaa",
}
/** Exit the Application */
private void exitForm(java.awt.event.Wi
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
UIManager.setLookAndFeel(U
}
catch (Exception e) {
System.exit(0);
}
new TableDemo().show();
}
// Variables declaration - do not modify
private javax.swing.JButton addButton;
private javax.swing.JButton changeButton;
private javax.swing.JButton deleteButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable theTable;
private List data = new ArrayList();
private int selectedRow;
private JPopupMenu popupmenu;
private JTable table;
private String colsName[] = {"RefNo", "Title", "Author", "Category", "Member ID", "Status"};
private JDesktopPane theDesktop = new JDesktopPane ();
private String[][] rowRec = {
{"1234", "Java", "JB", "Java", "vbourke", "available"},
{"5678", "Java2", "VB", "Java", "vblogs1", "available"},
{"0112", "Java3", "SB", "Java", "vblogs2", "available"},
{"3456", "Java4", "DB", "Java", "vblogs3", "available"},
{"7892", "Java5", "NB", "Java", "vblogs4", "available"},
};
// End of variables declaration
}
//SearchTableModel.java
package Logon;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.util.List;
public class SearchTableModel extends DefaultTableModel {
List data; // a list of MyObject's
private String[] columnNames;
/** Creates a new instance of MyTableModel */
public SearchTableModel(List d, String[] columnNames) {
this.data = d;
this.columnNames = columnNames;
System.out.println("length
}
public Object getTableObject(int index) {
return data.get(index);
}
public void setColumnName(int index, String name) {
if (index < columnNames.length)
columnNames[index] = name;
}
public boolean isCellEditable(int row, int col) {
return false;
}
public void addRow(SearchTableObject object) {
data.add(object);
fireTableRowsInserted(data
}
public void removeRow(int index) {
data.remove(index);
fireTableRowsDeleted(index
}
public Class getColumnClass(int col) {
return super.getColumnClass(col);
}
public int getRowCount() {
return data==null ? 0 : data.size();
}
public int getColumnCount() {
return columnNames.length;
}
public Object getValueAt(int row, int col) {
if ( row < 0 || row >= data.size() ) return null;
SearchTableObject myObj = (SearchTableObject) data.get(row);
if (col==0)
return myObj.getField1();
else if (col==1)
return myObj.getField2();
else if (col==2)
return myObj.getField3();
else if (col==3)
return myObj.getField4();
else if (col==4)
return myObj.getField5();
else if (col==5)
return myObj.getField6();
else return null;
}
// not needed if not editable:
public void setValueAt(Object value, int row, int col) {
if ( row < 0 || row >= data.size() )/*|| col!=0 )*/ return;
// only col=0 is editable (in this example)
SearchTableObject myObj = (SearchTableObject) data.get(row);
if (col==0)
myObj.setField1( (String)value );
else if (col==1)
myObj.setField2( (String)value );
else if (col==2)
myObj.setField3( (String)value );
else if (col==3)
myObj.setField4( (String)value );
else if (col==4)
myObj.setField5( (String)value );
else if (col==5)
myObj.setField6( (String)value );
fireTableCellUpdated(row, col);
}
public String getColumnName(int col) {
return columnNames[col];
}
}
//SearchTableObject.java
package Logon;
public class SearchTableObject {
private String field1 = "";
private String field2 = "";
private String field3 = "";
private String field4 = "";
private String field5 = "";
private String field6 = "";
/** Creates a new instance of MyTableObject */
public SearchTableObject() {
}
public SearchTableObject(String f1, String f2, String f3, String f4, String f5, String f6) {
field1 = f1;
field2 = f2;
field3 = f3;
field4 = f4;
field5 = f5;
field6 = f6;
}
public String getField1() { return field1; }
public String getField2() { return field2; }
public String getField3() { return field3; }
public String getField4() { return field4; }
public String getField5() { return field5; }
public String getField6() { return field6; }
public void setField1(String f1) { field1 = f1; }
public void setField2(String f2) { field2 = f2; }
public void setField3(String f3) { field3 = f3; }
public void setField4(String f4) { field4 = f4; }
public void setField5(String f5) { field5 = f5; }
public void setField6(String f6) { field5 = f6; }
}
Found the error:
public void setField6(String f6) { field5 = f6; } // you set field5 instead of 6
You see, that my question
>> Sure the object's setField4() is OK?
was not that stupid as it sounds? ;°)
Other remark:
In your mousePressed() function I would add
public void mousePressed(MouseEvent e){
if (!SwingUtilities.isRightMo useButton( e)) // <<<<< add this
return; // <<<<<
....
}
So that the menu only appears on a right-click
public void setField6(String f6) { field5 = f6; } // you set field5 instead of 6
You see, that my question
>> Sure the object's setField4() is OK?
was not that stupid as it sounds? ;°)
Other remark:
In your mousePressed() function I would add
public void mousePressed(MouseEvent e){
if (!SwingUtilities.isRightMo
return; // <<<<<
....
}
So that the menu only appears on a right-click
ASKER
Hi, thanks for that, looks better with the right mouse click. I went and changed it my application code here it didnt make any difference what so ever.
ASKER
field3 is the one that is being overwritten all the time.
doesnt make any sense!
doesnt make any sense!
>> I went and changed it my application code here
*it*? What?
>> it didnt make any difference what so ever.
Don't know what you mean.
*it*? What?
>> it didnt make any difference what so ever.
Don't know what you mean.
ASKER
I went and changed what you spotted was wrong above.
It worked fine when I changed it in the Demo version
that I posted above. But in my real application here
it still isnt working properly.
It worked fine when I changed it in the Demo version
that I posted above. But in my real application here
it still isnt working properly.
Sure you really run the *adapted* code?
ASKER
Yeah in the demo, I was overwritting field5 with field6
in my real app. field3 is being overritten by whatever is in field4 if update or field5 if update or field6 if updated.
It's acting really strange:
This is what I am changing
SearchTableModel model =
(SearchTableModel)table.ge tModel();
SearchTableObject obj =
(SearchTableObject)model.g etTableObj ect(select edRow);
obj.setField1("Changed");
obj.setField2("Changed too");
obj.setField3("Also changed...");
obj.setField4("New one1...");
obj.setField5("New one2...");
obj.setField6("New one3...");
model.fireTableRowsUpdated
(selectedRow, selectedRow);
in my real app. field3 is being overritten by whatever is in field4 if update or field5 if update or field6 if updated.
It's acting really strange:
This is what I am changing
SearchTableModel model =
(SearchTableModel)table.ge
SearchTableObject obj =
(SearchTableObject)model.g
obj.setField1("Changed");
obj.setField2("Changed too");
obj.setField3("Also changed...");
obj.setField4("New one1...");
obj.setField5("New one2...");
obj.setField6("New one3...");
model.fireTableRowsUpdated
(selectedRow, selectedRow);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Setfieldx() functions are as follows:
public void setField1(String f1) { field1 = f1; }
public void setField2(String f2) { field2 = f2; }
public void setField3(String f3) { field3 = f3; }
public void setField4(String f4) { field4 = f4; }
public void setField5(String f5) { field5 = f5; }
public void setField6(String f6) { field6 = f6; }
public void setField1(String f1) { field1 = f1; }
public void setField2(String f2) { field2 = f2; }
public void setField3(String f3) { field3 = f3; }
public void setField4(String f4) { field4 = f4; }
public void setField5(String f5) { field5 = f5; }
public void setField6(String f6) { field6 = f6; }
ASKER
Right all is sorted now. I did a reboot of my PC and everything seems to updating properly.
Thank you again for your help, it is very much appreciated.
Thank you again for your help, it is very much appreciated.
All right! :)
Please kindly close this Q by accepting
Please kindly close this Q by accepting
Thanks for accepting
Just update the corresponding entry in the table model behind the JTable