Re: JTable setValueAt problem
Ok, my code is written in VisualAge, and may look like scrabbled:
[code]
package count;
import java.text.*;
import java.util.*;
import java.awt.geom.Dimension2D;
/**
* Insert the type's description here.
* Creation date: (10/13/2006 12:27:24 PM)
* @author: Administrator
*/
public class TestTable extends javax.swing.JFrame {
private javax.swing.JPanel ivjJFrameContentPane = null;
private javax.swing.JButton ivjJButton1 = null;
private javax.swing.table.DefaultTableModel ivjDefaultTableModel1 =
null;
IvjEventHandler ivjEventHandler = new IvjEventHandler();
private javax.swing.JScrollPane ivjJScrollPane1 = null;
private javax.swing.JTable ivjScrollPaneTable = null;
private javax.swing.table.TableColumn ivjTableColumn1 = null;
private javax.swing.table.TableColumn ivjTableColumn2 = null;
private javax.swing.table.TableColumn ivjTableColumn3 = null;
private javax.swing.table.TableColumn ivjTableColumn4 = null;
private javax.swing.table.TableColumn ivjTableColumn5 = null;
class IvjEventHandler implements java.awt.event.ActionListener {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (e.getSource() == TestTable.this.getJButton1())
connEtoC1(e);
};
};
/**
* TestTable constructor comment.
*/
public TestTable() {
super();
initialize();
}
/**
* TestTable constructor comment.
* @param title java.lang.String
*/
public TestTable(String title) {
super(title);
}
/**
* connEtoC1:
(JButton1.action.actionPerformed(java.awt.event.ActionEvent) -->
TestTable.jButton1_ActionPerformed(Ljava.awt.event.ActionEvent;)V)
* @param arg1 java.awt.event.ActionEvent
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connEtoC1(java.awt.event.ActionEvent arg1) {
try {
this.jButton1_ActionPerformed(arg1);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
/**
* connPtoP1SetTarget: (DefaultTableModel1.this <-->
ScrollPaneTable.model)
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connPtoP1SetTarget() {
/* Set the target from the source */
try {
getScrollPaneTable().setModel(getDefaultTableModel1());
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
/**
* Return the DefaultTableModel1 property value.
* @return javax.swing.table.DefaultTableModel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.table.DefaultTableModel getDefaultTableModel1() {
if (ivjDefaultTableModel1 == null) {
try {
ivjDefaultTableModel1 = new
javax.swing.table.DefaultTableModel(5,5);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
return ivjDefaultTableModel1;
}
/**
* Return the JButton1 property value.
* @return javax.swing.JButton
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JButton getJButton1() {
if (ivjJButton1 == null) {
try {
ivjJButton1 = new javax.swing.JButton();
ivjJButton1.setName("JButton1");
ivjJButton1.setText("View");
ivjJButton1.setBounds(218, 325, 85, 25);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
return ivjJButton1;
}
/**
* Return the JFrameContentPane property value.
* @return javax.swing.JPanel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JPanel getJFrameContentPane() {
if (ivjJFrameContentPane == null) {
try {
ivjJFrameContentPane = new javax.swing.JPanel();
ivjJFrameContentPane.setName("JFrameContentPane");
ivjJFrameContentPane.setLayout(null);
getJFrameContentPane().add(getJButton1(), getJButton1().getName());
getJFrameContentPane().add(getJLabel1(), getJLabel1().getName());
getJFrameContentPane().add(getJLabel2(), getJLabel2().getName());
getJFrameContentPane().add(getJLabel3(), getJLabel3().getName());
getJFrameContentPane().add(getJLabel4(), getJLabel4().getName());
getJFrameContentPane().add(getJScrollPane1(),
getJScrollPane1().getName());
// user code begin {1}
ivjJFrameContentPane.setVisible(true);
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJFrameContentPane;
}
/**
* Return the JScrollPane1 property value.
* @return javax.swing.JScrollPane
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JScrollPane getJScrollPane1() {
if (ivjJScrollPane1 == null) {
try {
ivjJScrollPane1 = new javax.swing.JScrollPane();
ivjJScrollPane1.setName("JScrollPane1");
ivjJScrollPane1.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
ivjJScrollPane1.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
ivjJScrollPane1.setBounds(27, 88, 468, 199);
getJScrollPane1().setViewportView(getScrollPaneTable());
ivjJScrollPane1.setVisible(true);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
return ivjJScrollPane1;
}
/**
* Return the ScrollPaneTable property value.
* @return javax.swing.JTable
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JTable getScrollPaneTable() {
if (ivjScrollPaneTable == null) {
try {
ivjScrollPaneTable = new javax.swing.JTable(){
public boolean isCellEditable(int rowIndex, int vColIndex) {
return false;
}
};
ivjScrollPaneTable.setName("ScrollPaneTable");
getJScrollPane1().setColumnHeaderView(ivjScrollPaneTable.getTableHeader());
getJScrollPane1().getViewport().setBackingStoreEnabled(true);
ivjScrollPaneTable.setBounds(0, 0, 200, 200);
ivjScrollPaneTable.setAutoCreateColumnsFromModel(false);
ivjScrollPaneTable.addColumn(getTableColumn1());
ivjScrollPaneTable.addColumn(getTableColumn2());
ivjScrollPaneTable.addColumn(getTableColumn3());
ivjScrollPaneTable.addColumn(getTableColumn4());
ivjScrollPaneTable.addColumn(getTableColumn5());
getDefaultTableModel1().addColumn(getTableColumn1());
getDefaultTableModel1().addColumn(getTableColumn2());
getDefaultTableModel1().addColumn(getTableColumn3());
getDefaultTableModel1().addColumn(getTableColumn4());
getDefaultTableModel1().addColumn(getTableColumn5());
ivjScrollPaneTable.setVisible(true);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
return ivjScrollPaneTable;
}
/**
* Return the TableColumn1 property value.
* @return javax.swing.table.TableColumn
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.table.TableColumn getTableColumn1() {
if (ivjTableColumn1 == null) {
try {
ivjTableColumn1 = new javax.swing.table.TableColumn();
ivjTableColumn1.setHeaderValue("Cassette");
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
return ivjTableColumn1;
}
/**
* Return the TableColumn2 property value.
* @return javax.swing.table.TableColumn
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.table.TableColumn getTableColumn2() {
if (ivjTableColumn2 == null) {
try {
ivjTableColumn2 = new javax.swing.table.TableColumn();
ivjTableColumn2.setHeaderValue("Loaded");
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
return ivjTableColumn2;
}
/**
* Return the TableColumn3 property value.
* @return javax.swing.table.TableColumn
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.table.TableColumn getTableColumn3() {
if (ivjTableColumn3 == null) {
try {
ivjTableColumn3 = new javax.swing.table.TableColumn();
ivjTableColumn3.setHeaderValue("Dispensed");
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
return ivjTableColumn3;
}
/**
* Return the TableColumn4 property value.
* @return javax.swing.table.TableColumn
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.table.TableColumn getTableColumn4() {
if (ivjTableColumn4 == null) {
try {
ivjTableColumn4 = new javax.swing.table.TableColumn();
ivjTableColumn4.setHeaderValue("Rejected");
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
return ivjTableColumn4;
}
/**
* Return the TableColumn5 property value.
* @return javax.swing.table.TableColumn
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.table.TableColumn getTableColumn5() {
if (ivjTableColumn5 == null) {
try {
ivjTableColumn5 = new javax.swing.table.TableColumn();
ivjTableColumn5.setHeaderValue("Remaining");
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
return ivjTableColumn5;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(java.lang.Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to
stdout */
System.out.println("--------- UNCAUGHT EXCEPTION ---------");
exception.printStackTrace(System.out);
}
/**
* Initializes connections
* @exception java.lang.Exception The exception description.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() throws java.lang.Exception {
// user code begin {1}
// user code end
getJButton1().addActionListener(ivjEventHandler);
connPtoP1SetTarget();
}
/**
* Initialize the class.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
try {
setName("TestTable");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setSize(522, 375);
setTitle("ATM Counters");
setContentPane(getJFrameContentPane());
initConnections();
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
/**
* Comment
*/
public void jButton1_ActionPerformed(java.awt.event.ActionEvent
actionEvent) {
ivjScrollPaneTable.setValueAt("nosilac virusa gripa",0,4);
ivjScrollPaneTable.setValueAt("glupak",0,3);
ivjScrollPaneTable.setValueAt("budala",0,2);
ivjScrollPaneTable.setValueAt("svinja",0,1);
ivjScrollPaneTable.setValueAt("draginja",0,0);
System.out.println("setValue Tabela: ");
System.out.println("(0,0): "+ivjScrollPaneTable.getValueAt(0,0));
System.out.println("(0,1): "+ivjScrollPaneTable.getValueAt(0,1));
System.out.println("(0,2): "+ivjScrollPaneTable.getValueAt(0,2));
System.out.println("(0,3): "+ivjScrollPaneTable.getValueAt(0,3));
System.out.println("(0,4): "+ivjScrollPaneTable.getValueAt(0,4));
/*Vector data = new Vector();
data.add(0,"draginja");
data.add(1,"svinja");
data.add(2,"budala");
data.add(3,"glupak");
data.add(4,"nosilac virusa gripa");
System.out.println("Vektor sa podacima: ");
System.out.println(data);
ivjDefaultTableModel1.insertRow(0,data);
System.out.println("insertRow Tabela: ");*/
System.out.println("(0,0): "+ivjScrollPaneTable.getValueAt(0,0));
System.out.println("(0,1): "+ivjScrollPaneTable.getValueAt(0,1));
System.out.println("(0,2): "+ivjScrollPaneTable.getValueAt(0,2));
System.out.println("(0,3): "+ivjScrollPaneTable.getValueAt(0,3));
System.out.println("(0,4): "+ivjScrollPaneTable.getValueAt(0,4));*/
return;
}
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
TestTable aTestTable;
aTestTable = new TestTable();
aTestTable.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
};
});
aTestTable.show();
java.awt.Insets insets = aTestTable.getInsets();
aTestTable.setSize(aTestTable.getWidth() + insets.left +
insets.right, aTestTable.getHeight() + insets.top + insets.bottom);
aTestTable.setVisible(true);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of
javax.swing.JFrame");
exception.printStackTrace(System.out);
}
}
}[\code]