advanced repalcement for TableModel in java swings

advanced repalcement for TableModel in java swings

Hi, Is there any advanced replacement for java TableModel.I want to display the search results ,for that i want better thing than TableModel.ould u please suggest something?

View Answers

August 8, 2011 at 1:23 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);
    }
}

August 8, 2011 at 6:57 PM

Hi, I want to display the search result in JTable.Don't want to display hard coded data. we dont know how many record has been searched,so I want a dynamically changed JTable according to the search data.

Ads









Related Tutorials/Questions & Answers:
advanced repalcement for TableModel in java swings
advanced repalcement for TableModel in java swings  Hi, Is there any advanced replacement for java TableModel.I want to display the search results ,for that i want better thing than TableModel.ould u please suggest
Java Swings
Java Swings  I am doing one project on java Swings, in this i have created one jframe where i defined some JButtons and Jcombobox's, here i need to insert one JTable with headers(IN CURRENT JFrame only).pls help me urgently
Advertisements
java swings
java swings  Hi, I need a sample code for once click the exit tab the frame window will be closed. Instead of button close i need tab close option.Please send the sample code immediately.......?Its very urgent........ Thanks
java swings
java swings  hi... I am having multiple swing forms.. when i click on a button another form is going to opening but it is opening as different form... Now i want it to be open dynamically instead separately.... Is there any
java swings
java swings  how can we use the shared locks of dbms in java? I am working on a mini project which is based on the eamcet councilling .i am struck with a problem where if a student select a college and a branch and sees
java swings
java swings  Hi, I have one class file using three panel methods,the three methods is used for three tabs.then how can i set the background image.Please send the sample code for me. I already posted two questions,but i didnt get
java swings
java swings  Hi, I need the sample code for how to set the background image using jframe and also set the jtext field and jlable boxes under the bachground image. Please send the code immediately,its very urgent.Please send me
Advanced Java
Advanced Java   What is the difference between byte code generated between that of Legacy collections and Generics
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
advanced java
advanced java  a program to download a web page
SWINGS
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
Advanced java
Advanced java  I need to add a functionality in my project : when attendance of a student comes to a min allowed limit a message is automatically sent to his/her parent mobile no. please help or provide me the code if possible
java swings - JavaMail
java swings  Hi sir,i am doing a project on swings,i don't have any...://www.roseindia.net/java/example/java/swing/GrideComponents.shtml http://www.roseindia.net/java/example/java/swing/AbsCoordinate.shtml http://www.roseindia.net
swings - Java Beginners
for this in google, but i got very difficult programs. i am beginner in java swings . i want...); } } For more information, visit the following link: http://www.roseindia.net/java/example/java/swing/ Thanks
Advanced Java Tutorials in 2017
Advanced Java Tutorials in 2017  Hi, What all Advanced Java tutorials I should learn in 2017? Thanks
Java Swings - Java Beginners
Java Swings  hi , I am doing project using netbeans. I have a combobox . I want to add items in that combobox from a method.For this i found... code: http://www.roseindia.net/java/example/java/swing
java swings - Java Beginners
java swings  Hi, I need the code for how can i set the joptionpane color(background and foreground). can i set the delay time for joptionpane display. Please send the code .its urgent. Thanks, Valarmathi
java swings - Java Beginners
java swings  hi, I send two questions ,but i didnt reply .please reply me back. I need the jfiledialog select option is only for directory... c:/valar/ only. This code is only for c:/valar/some.txt,pdf... import
swings - Java Beginners
Exception in thread "main" Exception in thread "main" Java Result: 1 BUILD SUCCESSFUL... it.  Hi Friend, It seems that either you have saved your java file... your java file is in tools folder or not. Thanks   Visit this URL
Java swings - Swing AWT
Java swings  i have the following class .In that class i has two panels,panel1and panel2.panel1 contains an image.i want drag it in panel2(gray background).but i dont want to remove the image from panel1.i want
Are J2EE and Java Advanced the same?
Are J2EE and Java Advanced the same?  Hi, I am checking J2EE and Advanced Java. Are J2EE and Java Advanced the same? Thanks   Hi, J2EE... application development. It includes JSP, Servlet, JDBC, EJB etc.. Advanced Java
want a program for date picker by using java swings
want a program for date picker by using java swings  to write a program for the date picker by using java swings.any one please help me by providing the code to this java date picker by using the java swings.previously a program
What are the best online advanced Java tutorials?
What are the best online advanced Java tutorials?  Hi, Just learned Core Java and now I want to learn Advanced Java. What are the best online advanced Java tutorials? Thanks   Hi, Advanced Java is next step towards
Advanced Java Training
Advanced Java Training Advanced Java Programming Course for the Java.... Advanced Java Training course will help in learning the Advanced concepts of Java.... Prerequisites of Advanced Java Training Working knowledge of Core Java
i have an ques. of advanced java
i have an ques. of advanced java  write a wap to implement AWT by login form
File format validation and text field validation in java swings
File format validation and text field validation in java swings   i am reading a jpg image file throuh jfilechooser in java swings,when we press... 'please select jpg file only' plz give me the code in swings. Please
What is the best site for advanced Java programming
What is the best site for advanced Java programming  Hi, I am... Java tutorials in Advanced Java programming so that learn it easily.... What is the best site for advanced Java programming? Where to learn Advanced Java
JSP & Swings
JSP & Swings  How to integrate jsp and swings
What is difference between Core Java and Advanced Java?
What is difference between Core Java and Advanced Java?  Hi, I want to know about Core Java and Advanced Java. How should I learn these technologies? What is difference between Core Java and Advanced Java? Thanks   
What is difference between Core Java and Advanced Java?
What is difference between Core Java and Advanced Java?  Hi, I want to know about Core Java and Advanced Java. How should I learn these technologies? What is difference between Core Java and Advanced Java? Thanks   
swings question
swings question  how to change the background color with the help of color values by using swings

Ads