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
How to create arrays in JavaScript?
JavaScript array multidimensional
How to add JTable in JPanel
To store value in session & display it
JavaScript array multidimensional
store dynamic generated textbox value into database
How to concatenate two arrays in Java?
How to insert rows in jTable?
swap two integer arrays
swap two integer arrays
swap two integer arrays
Php Array Multidimensional
store value in checkbox from gridview
JTable
Arrays
arrays
multidimensional data cube - Java Beginners
how to compare 2 arrays using java?
Arrays
How to use JTable with MS-Access
How to use JTable with MS-Access
store html value in the sqllite 3 php
how to create a header in jtable using java swing
JTable
jtable
How to store image into database
How to store an image in database
Multidimensional Array Java
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row
JTable
JTable
Arrays
arrays
Code to store SubCombo box value - Development process
Comparing Arrays
JTable
Store combo box value - Development process
ModuleNotFoundError: No module named 'multidimensional_urlencode'
ModuleNotFoundError: No module named 'multidimensional_urlencode'
Arrays
JTable
How to create a JTable cell containing Image hyperlink?

Ads