Jtable-Java

Ads
 

Jtable-Java

Hi all,I have a Jtable And i need to clear the data in the table .I only Need to remove the data in the table.not the rows.Please help me.

View Answers

September 2, 2011 at 7:35 PM

No answers Yet.... :(


September 3, 2011 at 11:00 AM

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

public class RemoveDataFromTable{
JTable table;
JButton button;
public static void main(String[] args){
new RemoveDataFromTable();
}
public RemoveDataFromTable(){
JFrame frame = new JFrame("Getting Cell Values in JTable");
JPanel panel = new JPanel();
String data[][] = {{"Angelina","Mumbai"},{"Martina","Delhi"}};

String col[] = {"Name","Address"};
DefaultTableModel model = new DefaultTableModel(data, col);
table = new JTable(model);
JScrollPane pane = new JScrollPane(table);
button=new JButton("Remove Data");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
int index=1;
int count=table.getRowCount();
for(int i=0;i<count;i++){
SetData("",i, 0);
  SetData("",i, 1);
}
}
});
panel.add(pane);
panel.add(button);
frame.add(panel);
frame.setSize(500,500);
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void SetData(Object obj, int row_index, int col_index){
  table.getModel().setValueAt(obj,row_index,col_index);
}
}

Ads









Related Tutorials/Questions & Answers:
JTABLE OF JAVA
JTABLE OF JAVA  i have a jtable in java,i have used checkbox in jtable. now i want to add(submit) only those records that i have checked by checkbox how? i want small example with coding
jtable in java swing
jtable in java swing  hai friends... i am creating 1 GUI having 1 table, that table contain 3 fields(columns) and 10 rows.. user can enter values in the first 2 columns. The 3rd column is the concatenation of first 2 column
Advertisements
Jtable-Java
Jtable-Java  Hi all,I have a Jtable And i need to clear the data in the table .I only Need to remove the data in the table.not the rows.Please help me
Java Swing Tutorial - Learning Java Swing programming step by step
on mouse click Java swing: Export excel sheet data to JTable... database Java Swing Create XML file Java convert jtable... Java Password Field JTable Display Data From MySQL
Java Swing Tutorial - Learning Java Swing programming step by step
on mouse click Java swing: Export excel sheet data to JTable... database Java Swing Create XML file Java convert jtable... Java Password Field JTable Display Data From MySQL
Java Swing Tutorial - Learning Java Swing programming step by step
on mouse click Java swing: Export excel sheet data to JTable... database Java Swing Create XML file Java convert jtable... Java Password Field JTable Display Data From MySQL
search filter and JTable
my question is: how can i make search data in JTable of java? i wan to search records in table or textfield but the data display in JTable. Note: i dont...","Contact No","Email"}; JTable table=new JTable(data,labels
How to insert and update all column values of database from jtable.
{ UIManager.setLookAndFeel("Interactive Jtable In Java Swing"); } catch(Exception e...How to insert and update all column values of database from jtable.  ... is shown in the jtable.. of my jframe window.Now as per my requirement i have to add
Sitemap Core Java Tutorial Section
Questionmark operator  | Java JVM | Java JTable | Java JRE Downloads... Map | Business Software Services India Java Tutorial Section Core Java... | JDK 6 Tutorial | Java UDP Tutorial | Java Threading Tutorial | Java 5
How to insert and update all column values of database from jtable.
{ UIManager.setLookAndFeel("Interactive Jtable In Java Swing"); } catch(Exception e...How to insert and update all column values of database from jtable.  ... in the jtable.. of my jframe window.Now as per my requirement i have to add
How to insert and update all column values of database from jtable.
{ UIManager.setLookAndFeel("Interactive Jtable In Java Swing"); } catch(Exception e...How to insert and update all column values of database from jtable.  ... in the jtable.. of my jframe window.Now as per my requirement i have to add

Ads