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.









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
Advanced Java
Advanced Java   What is the difference between byte code generated between that of Legacy collections and Generics
Advertisements
advanced java
advanced java  a program to download a web page
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
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
Advanced Java Tutorials in 2017
Advanced Java Tutorials in 2017  Hi, What all Advanced Java tutorials I should learn in 2017? Thanks
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
java swings - Java Beginners
java swings   Do you want to add textfields on the JPanel
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
java swings - Java Beginners
java swings   Hi, I need the code for click the refresh button then list values will be refresh.Please send the code ........... Thanks, Valarmathi
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
about swings - Java Beginners
about swings   Dear sir,Good evening, i am doing mca sir,i am doing the project in swings,so plz provide the material about swings sir...: http://www.roseindia.net/java/example/java/swing/ Hope
java swings - Java Beginners
java swings   Hi, I need the code for joptionpane with jcombobox. my requirement is click on add button,one joptionpane will come.from the option pane i need to select the combobox values. Please send the sample code
SWINGS
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
java swings - Swing AWT
write the code for bar charts using java swings.  Hi friend, I am...java swings  I am doing a project for my company. I need a to show.... http://www.roseindia.net/java/example/java/swing/draw-simple-bar
java swings - Java Beginners
java swings   Hi, I already posted the question for three times.... I have two listboxes.If i select first value in the first listbox and moved to second listbox.The next time the same value will not able to move the first
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
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 TrainingADS_TO_REPLACE_1 Working knowledge
java swings - Java Beginners
java swings   Hi, I have two classes(two tabbed panes). how can i get the one class jtextfield value into another class method. Please send the code as sson as possible. Thanks, Valarmathi  Hi Friend, Try
i have an ques. of advanced java
i have an ques. of advanced java  write a wap to implement AWT by login form
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
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
java swings - Java Beginners
java swings   Hi, This is my code. How can i set the jtextfield...", Font.BOLD, 12)); javapathname = new JLabel("Java Path"); javatextpath = new JTextField(33); javatextpath.setToolTipText("Java Installation Path
java swings - Java Beginners
java swings   Hi , I have two listboxes.I want to move one listbox... correct the value and send it to me. This is my java code package...,because place the xml file in the c:/ directly and run the java code
java swings - Java Beginners
java swings   hi, I posted the same question two times,but i didnt get the reply. Please change the jframe look and feel type of code.please send the code immediately. This is my code package com.zsl.ibm.mqtool; import
swings - Java Beginners
swings  how to upload images using swings   Hi Friend, Try the following code: import java.awt.*; import java.io.*; import javax.swing.*; import java.awt.image.*; import java.awt.event.*; import
Java Swings-awt - Swing AWT
Java Swings-awt  Hi, Thanks for posting the Answer... I need to design a tool Bar which looks like a Formating toolbar in MS-Office Winword(Standard & Formating) tool Bar. Please help me... Thanks in Advance
swings - Java Beginners
swings   how t upload images in swings. thanks   Hello Friend, Try the following code: import java.io.*; import java.sql.*; import java.util.*; import java.awt.*; import java.awt.event.*; import
java-swings - Java Beginners
java-swings  How to write a program for JTree within a JTable cell in java swings.A table should be displayed when i click on the cell of the table. Please help. Thank u
java swings - Java Beginners
java swings  Hi, I need simple code for JButton JOptionPane.Please send the code. Thanks, Valarmathi
Java-Swings - Java Beginners
Java-Swings  How to set size of JButton depending on it's dynamic caption in java? Here caption is not known at desing time it is geerated at runtime.  Hi friend, Please give in details and full source code where
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
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 already send the question. But i didnt get the reply. I can't able to set the jfiledialog directory selection in the textbox. Please send the code urgently. Thanks, Valarmathi
java swings - Java Beginners
java swings  Hi, I have two listboxes .Move the one listbox value into another listbox using add button.Move the value one by one into another listbox.Please give the code using jpanel. Thanks, Valarmathi
java swings - Java Beginners
java swings  Hi, I need the code for how to jlistbox value enable disable . please send the code as soon as possible. Please its urgent. Thanks, Valarmathi
Java-Swings - Java Beginners
Java-Swings  How to set the size of a JButton,JLabel depending on it's caption?  Hi, import javax.swing.*; import java.awt....://www.roseindia.net/java/example/java/swing/ Thanks
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 have JoptionPane combobox,in the joptionpane jcombobox have array of values. If i select one value from the joptionpane combobox ,then the selected value will be displayed in the listbox. Please send
Java-swings - Java Beginners
Java-swings  How to move JLabels in a Frame  Hi friend, plz specify in detail. I am sending you a text drag code one textarea...); } } ------------------------------------------------- Visit for more information: http://www.roseindia.net/java/example/java
java swings - Java Beginners
java swings  Hi, How can i set the color in joptionpane. Please send the code as soon as possible. Thanks, valarmathi  Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; public
java swings - Java Beginners
java swings  Hi, I need the sample code for bulk of text added using jpanel. I need the code urgent. Please sedn the code as soon as possible. Thanks, Valarmathi   Hi Friend, Do you want to add textfields
Java Swings - Java Beginners
Java Swings  Hi, I am sending example button program. Please check it and give answer. I have an urgent requuirement with this. //The sample program import javax.swing.*; class ButtonSizeTest extends JFrame { JButton
java swings - Java Beginners
java swings  how to send the data in database using java swing. Example : how to design the registration page using java swing, and how to write the coding to store the data into data base. Plz help........ 
java swings - Java Beginners
java swings  Hi, I have two listboxes.I need to move the lisstbox values from one list to another one(ie first listbox to second listbox).I wnat the code for duplicate value no need to move the first listbox into second
java swings - Java Beginners
java swings  Hi, I need to Pass the two arguments from the joptionpane message dialog . JOptionPane.showMessageDialog(listTransferButton, "Succesfully Migrated the +listvalue Active MQ to IBM MQ", "Migration

Ads