Share on Google+Share on Google+

tharaka Nandakumara
Jtable-Java
2 Answer(s)      5 years and 7 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.

Ads

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
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
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
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
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads