Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

reading from a jtable to a textArea

i am stuck i will like to read from cell from a jtable to a text area then read from two rows from a jtable to another textArea.  
0
mnninrod
Asked:
mnninrod
  • 6
  • 6
  • 4
1 Solution
 
CEHJCommented:
textArea.setText((String)table.getModel().getValueAt(rowIndex, columnIndex));
0
 
objectsCommented:
for (int i=row1; i<=row2; i++)
{
   for (int j=0; j<table.getColumnCount(); j++)
   {
      ta.append(table.getValueAt(i, j)+" ");
   }
   ta.append("\n");
}
0
 
objectsCommented:
where row1 and row2 are the range of rows you want to display.
you can change the 2nd loop in a similiar way if you want to limit the column range.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mnninrodAuthor Commented:
i am having a problem from reading from a jtable to the textfield area. when the start button which is jbutton2 is pressed it should copy the value 0 from the jtable to  jtextfield5 the value from jtextfield5 to jtextfield7. copy the value 01999 from the jtable to jtextfield2 and copy the value from jtextfield2 to jtextfield6 and increment the value in jtextfied5 by 1.
when using cehj comment i am getting a java lang error . i am using netbeans to run the code but editing it in j++. i am stuck here  for sometime i need help if only i can read from the jtabe i would be able to start.

here is my code

import java.awt.event.ActionListener;
import java.awt.event.WindowListener;
public class microprocessor extends javax.swing.JFrame {
   
    /** Creates new form NewJFrame */
    public microprocessor() {
        initComponents();
    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        jFrame1 = new javax.swing.JFrame();
        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextArea1 = new javax.swing.JTextArea();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        pause = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jTable1 = new javax.swing.JTable();
            setTitle("microprocessor");

        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("continue");
        jButton1.setText("continue");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 470, -1, -1));

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 70, 120, 20));

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 200, 110, 20));

        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 70, 110, 20));

        getContentPane().add(jTextArea1, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 140, -1, -1));

        jTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField4ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 110, 190, 80));

        jTextField5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField5ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 100, 80, 20));

        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField6, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 430, 170, 20));

        getContentPane().add(jTextField7, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 200, 90, 20));

        pause.setText("pause");
        pause.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pauseActionPerformed(evt);
            }
        });
        pause.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                pauseMousePressed(evt);
            }
        });

        getContentPane().add(pause, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 470, -1, -1));
            jButton2.setMnemonic('G');

        jButton2.setText("start");
        jButton2.addActionListener(new  java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                        //if (evt.getSource()==jButton2)
                        //{
                              //jTextField5.setText((String)jTable1.getModel().getValueAt(1, 2));
                        //}
               jButton2ActionPerformed(evt);
            }
        });

        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 470, -1, -1));

        jLabel1.setText("A");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 50, -1, -1));

        jLabel2.setText("mainmemory");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 240, -1, -1));

        jLabel3.setText("ir");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 410, 10, 10));

        jLabel4.setText("MDR");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 180, -1, -1));

        jLabel5.setText("B");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 50, -1, -1));

        jLabel6.setText("MAR");
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 180, -1, -1));

        jLabel7.setText("PC");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(700, 80, -1, -1));

        getContentPane().add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                                                                                                 
                                                                                     
            new Object [][] {
                {new Integer(000), new Integer(01), new Integer(999)},
                {new Integer(001), new Integer(20) ,new Integer(997)},
                {new Integer(002), new Integer(02), new Integer(999)},
                        {new Integer(003), new Integer(0), new Integer(0)},
                        {new Integer(0), new Integer(0), new Integer(0)},
                        {new Integer(997), new Integer(01), new Integer(200)},
                        {new Integer(998), new Integer(00), new Integer(300)},                                                                        
                      {new Integer(997), new Integer(01), new Integer(807) }},
         //   },
                  //String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
             new String [] {
                                           "Title 1", "Title 2", "Title 3"}
            //}
        ));
        getContentPane().add(jTable1, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 260, -1, -1));

        pack();
    }//GEN-END:initComponents

    private void pauseMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pauseMousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_pauseMousePressed

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            jTextField5.setText(( String )(jTable1.getModel().getValueAt(0,0)));
            
            //GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField6ActionPerformed

    private void pauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_pauseActionPerformed

    private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
            //jTextField5.setText((String)jTable1.getModel().getValueAt(1, 2));
            //getContentPane().setDefaultButton(jButton2);
            
            //jText.setText((String)jTable1.getModel().getValueAt(0, 0));
            
            //GEN-FIRST:event_jTextField5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField5ActionPerformed

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField4ActionPerformed

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField3ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed
   
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new microprocessor().setVisible(true);
            }
        });
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JButton pause;
    // End of variables declaration//GEN-END:variables
   
}
0
 
mnninrodAuthor Commented:
i am having a problem from reading from a jtable to the textfield area. when the start button which is jbutton2 is pressed it should copy the value 0 from the jtable to  jtextfield5 the value from jtextfield5 to jtextfield7. copy the value 01999 from the jtable to jtextfield2 and copy the value from jtextfield2 to jtextfield6 and increment the value in jtextfied5 by 1.
when using cehj comment i am getting a java lang error . i am using netbeans to run the code but editing it in j++. i am stuck here  for sometime i need help if only i can read from the jtabe i would be able to start.

here is my code

import java.awt.event.ActionListener;
import java.awt.event.WindowListener;
public class microprocessor extends javax.swing.JFrame {
   
    /** Creates new form NewJFrame */
    public microprocessor() {
        initComponents();
    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        jFrame1 = new javax.swing.JFrame();
        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextArea1 = new javax.swing.JTextArea();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        pause = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jTable1 = new javax.swing.JTable();
            setTitle("microprocessor");

        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("continue");
        jButton1.setText("continue");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 470, -1, -1));

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 70, 120, 20));

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 200, 110, 20));

        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 70, 110, 20));

        getContentPane().add(jTextArea1, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 140, -1, -1));

        jTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField4ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 110, 190, 80));

        jTextField5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField5ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 100, 80, 20));

        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });

        getContentPane().add(jTextField6, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 430, 170, 20));

        getContentPane().add(jTextField7, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 200, 90, 20));

        pause.setText("pause");
        pause.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pauseActionPerformed(evt);
            }
        });
        pause.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                pauseMousePressed(evt);
            }
        });

        getContentPane().add(pause, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 470, -1, -1));
            jButton2.setMnemonic('G');

        jButton2.setText("start");
        jButton2.addActionListener(new  java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                        //if (evt.getSource()==jButton2)
                        //{
                              //jTextField5.setText((String)jTable1.getModel().getValueAt(1, 2));
                        //}
               jButton2ActionPerformed(evt);
            }
        });

        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 470, -1, -1));

        jLabel1.setText("A");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 50, -1, -1));

        jLabel2.setText("mainmemory");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 240, -1, -1));

        jLabel3.setText("ir");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 410, 10, 10));

        jLabel4.setText("MDR");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 180, -1, -1));

        jLabel5.setText("B");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 50, -1, -1));

        jLabel6.setText("MAR");
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 180, -1, -1));

        jLabel7.setText("PC");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(700, 80, -1, -1));

        getContentPane().add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                                                                                                 
                                                                                     
            new Object [][] {
                {new Integer(000), new Integer(01), new Integer(999)},
                {new Integer(001), new Integer(20) ,new Integer(997)},
                {new Integer(002), new Integer(02), new Integer(999)},
                        {new Integer(003), new Integer(0), new Integer(0)},
                        {new Integer(0), new Integer(0), new Integer(0)},
                        {new Integer(997), new Integer(01), new Integer(200)},
                        {new Integer(998), new Integer(00), new Integer(300)},                                                                        
                      {new Integer(997), new Integer(01), new Integer(807) }},
         //   },
                  //String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
             new String [] {
                                           "Title 1", "Title 2", "Title 3"}
            //}
        ));
        getContentPane().add(jTable1, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 260, -1, -1));

        pack();
    }//GEN-END:initComponents

    private void pauseMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pauseMousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_pauseMousePressed

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            jTextField5.setText(( String )(jTable1.getModel().getValueAt(0,0)));
            
            //GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField6ActionPerformed

    private void pauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_pauseActionPerformed

    private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
            //jTextField5.setText((String)jTable1.getModel().getValueAt(1, 2));
            //getContentPane().setDefaultButton(jButton2);
            
            //jText.setText((String)jTable1.getModel().getValueAt(0, 0));
            
            //GEN-FIRST:event_jTextField5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField5ActionPerformed

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField4ActionPerformed

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField3ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed
   
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new microprocessor().setVisible(true);
            }
        });
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JButton pause;
    // End of variables declaration//GEN-END:variables
   
}
0
 
CEHJCommented:
What happens when you comment out

//jTextField5.setText(( String )(jTable1.getModel().getValueAt(0,0)));


?
0
 
mnninrodAuthor Commented:
when i use jTextField5.setText(( String )(jTable1.getModel().getValueAt(0,0)));

i get this error java.lang.ClassCastException . When i freeze it nothing happens coz what i am interested in is reading from the jtable to the jtextarea.

   
0
 
objectsCommented:
> when i use jTextField5.setText(( String )(jTable1.getModel().getValueAt(0,0)));
> i get this error java.lang.ClassCastException

Use the code I posted instead.

0
 
objectsCommented:
jTextField5.setText(jTable1.getValueAt(0,0)+"");
0
 
mnninrodAuthor Commented:
the line that object wrote is working. but i am only left with copying two adjacent cells together  the value 01999 to jtextfield7 than i think i can start.
0
 
mnninrodAuthor Commented:
the line that object wrote is working. but i am only left with copying two adjacent cells together  the value 01999 from jtablefield to jtextfield7 than i think i can start.
0
 
CEHJCommented:
>>
i get this error java.lang.ClassCastException
when i use jTextField5.setText(( String )(jTable1.getModel().getValueAt(0,0)));
>>

That's because you used the code i posted from before, and i hadn't seen your model then. You have Integer, not String in your model, so the cast would be to Integer. You can in fact do

jTextField5.setText(jTable1.getModel().getValueAt(0,0).toString());

0
 
objectsCommented:
the code I originaslly posted can be used to copy a range of values.

or for two adjacent cells you could also use something like:

jTextField7.setText(jTable1.getValueAt(0,0)+""+jTable1.getValueAt(0,1));
0
 
CEHJCommented:
If you want to display those leading zeros in your model, then you need to use String, as if you're using Integer, they are redundant
0
 
objectsCommented:
> That's because you used the code i posted from before, and i hadn't seen your model

no need to see the model

> jTextField5.setText(jTable1.getModel().getValueAt(0,0).toString());

that code could also cause problems.


0
 
mnninrodAuthor Commented:
i will finish the code before friday and i will post it.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now