how to store jtable value in multidimensional array?

how to store jtable value in multidimensional array?

i want to store the value of jtable in multidimensional array,with type double. how to store jtable value in multidimensional array?

View Answers

March 16, 2011 at 4:35 PM

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;

class GetJTableData{
    public static Object[][] getTableData (JTable table) {
    DefaultTableModel dtm = (DefaultTableModel) table.getModel();
    int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
    Object[][] tableData = new Object[nRow][nCol];
    for (int i = 0 ; i < nRow ; i++)
        for (int j = 0 ; j < nCol ; j++)
            tableData[i][j] = dtm.getValueAt(i,j);
    return tableData;
}
    public static void main(String[] args) 
    {
        JFrame frame = new JFrame("Getting Cell Values in JTable");
    frame.setLayout(null);
    String data[][] = {{"A","Delhi"},
                      {"B","Mumbai"},
                      {"C","Chennai"},
                      {"D","Kolkata"}};
    String col[] = {"Name","Address"};    
    DefaultTableModel model = new DefaultTableModel(data, col);
    final JTable table = new JTable(model);
    JTableHeader header = table.getTableHeader();
    header.setBackground(Color.yellow);
    JScrollPane pane = new JScrollPane(table);
    pane.setBounds(10,10,300,200);
    JButton b=new JButton("Get");
    b.setBounds(10,250,80,20);
    frame.add(pane);
    frame.add(b);
    b.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
Object[][] A=getTableData(table);
for (int i=0 ; i < A.length ; i++)
        {     System.out.println();
            for  (int j=0 ; j < A[i].length ; j++){
                System.out.print(A[i][j].toString()+" ");
                  }
        }
     }
    });
    frame.setSize(350,350);
    frame.setUndecorated(true);
    frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
    frame.setVisible(true);
    }
}









Related Tutorials/Questions & Answers:
how to store jtable value in multidimensional array?
how to store jtable value in multidimensional array?
Advertisements
multidimensional arrays
How to Append Arrays in PHP
How to collect Java input field value display into Jtable?
PHP Push MultiDimensional Array
How to Store Float Value into Access Database - Java Beginners
How to store two integer value in a separate file and retrieve those values
JavaScript array multidimensional
How to create arrays in JavaScript?
How to add JTable in JPanel
To store value in session & display it
JavaScript array multidimensional
store dynamic generated textbox value into database
swap two integer arrays
swap two integer arrays
swap two integer arrays
How to concatenate two arrays in Java?
Php Array Multidimensional
How to insert rows in jTable?
JTable
store value in checkbox from gridview
Arrays
arrays
multidimensional data cube - Java Beginners
Arrays
JTable
store html value in the sqllite 3 php
how to compare 2 arrays using java?
jtable
how to create a header in jtable using java swing
JTable
JTable
How to use JTable with MS-Access
How to use JTable with MS-Access
Multidimensional Array Java
Arrays
arrays
Comparing Arrays
JTable
Code to store SubCombo box value - Development process
JTable
Arrays
Store combo box value - Development process
ModuleNotFoundError: No module named 'multidimensional_urlencode'
ModuleNotFoundError: No module named 'multidimensional_urlencode'
I want to store the value of local variable into Global variable
arrays
java arrays
C Array copy example

Ads