Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


tharaka Nandakumara
Jtable-Java
2 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners


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.


Advertisement
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);
}
}


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
JTable - Java Beginners
JTable search example  I've problem about JTable, i wan to search records when i types words in JTable cell,can u give the source code.I'm Beginner and i start begins learning java programming.Please send the example into my
JTable - Java Beginners
(); stat3.close(); JTable table = new JTable(data, columnNames... the following links: http://www.roseindia.net/java/example/java/swing/CellGap.shtml http://www.roseindia.net/java/example/java/swing
JTable - Java Beginners
JTable  Hi, I have some problem with JTable. On show All button hit.... my problem is with Jtable, sometimes it is visible and sometimes it is not. when...(); JTable table = new JTable(data, columnNames); sp=new JScrollPane(table
JTable - Java Beginners
want my JTable on the panel. and i also want to increase height and width... back. thank you very much sir for your help. i am new to java and your help...); } res2.close(); stat3.close(); JTable table = new JTable(data
JTable - Java Beginners
JTable Search Filter  Hi,i wanted to add a search filter in my JTable application.Thanks in Advance!!  i'means using database access,when...=============================================================================i press the enter button into JTable cell and focus
JTable - Java Beginners
JTable  can we merge two cells of one row in jtable
update a JTable - Java Beginners
update a JTable   how to update a JTable with Mysql data through user... in an updatable JTable You would create the table as follows: conn... = new ResultSetTableModel(rs); table = new JTable(model
update a JTable - Java Beginners
update a JTable   i have tried your advice as how to update a JTable... main(String args[]) { JTable table; Connection con = null..."); ResultSetTableModel model = new ResultSetTableModel(rs); table = new JTable(model
JTable in java - Java Beginners
JTable in java  Sir , I have created an application with a JTable showing the records of an MS Access database table. On the same frame I have... given one , JTable table; ....... .... table.print(); Here the error
adding data to the database with the use of jtable - Java Beginners
adding data to the database with the use of jtable  how can i add data to the database with the use of jtable. and also can able to view the records in the database in the table.. tnx :G
adding data to the database with the use of jtable - Java Beginners
adding data to the database with the use of jtable  how can i add data to the database with the use of jtable. and also can able to view the records in the database in the table.. tnx :G
How To Display MS Access Table into Swing JTable - Java Beginners
How To Display MS Access Table into Swing JTable  How to Display Records From MS Access Database To JTable. Plz Help Me  Hi Friend...){ System.out.println(e); } JTable table = new JTable(data, columnNames); TableColumn
Creating a JTable Component
of JTable and it's components. JTable: The JTabel component is more flexible Java... the simple JTable on the java swing frame with the help of some java methods. To create a JTable component, you need a java swing frame. The JTable based on the frame's
About java
About java   how we insert our database data into the jTable in java or how we show database content into the JTable in java   Hi Friend, Try the following code: import java.io.*; import
Getting the Number of Rows and Columns in JTable
;       In this java tutorial you will learn how to get the number of rows and columns in JTable.  This program simply helps us for getting the number of rows and columns from the JTable by using
Add XML to JTable
Add XML to JTable In this section, you will learn how to access the contents or data of xml document and display its information into the jtable. Java... all the xml file data into the JTable . Here is the person.xml file
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
Getting Cell Values in a JTable
Getting Cell Values in a JTable     ... values in a JTable component. It is a same as setting the cell values in a JTable... to get the cell values in a JTable. This program creates a JTable that contains some
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
Java Swing Tutorials
JTable: The JTabel component is more flexible Java Swing... tabular format. The Java swing implements tables by using the JTable class... of Rows and columns in JTable In this java tutorial you will learn how
 

 

 

DMCA.com