creation of table using a Java swing

creation of table using a Java swing

how to create a table dynamically in Java swing?

View Answers

November 13, 2010 at 10:50 AM

Hi Friend,

Try the following code:

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

public class JTableDatabase {
public static void main(String[] args) {
Vector columnNames = new Vector();
Vector data = new Vector();
JPanel p=new JPanel();
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root", "root");
String sql = "Select * from data";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery( sql );
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
for (int i = 1; i <= columns; i++) {
columnNames.addElement( md.getColumnName(i) );
}
while (rs.next()) {
Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++){
row.addElement( rs.getObject(i) );
}
data.addElement( row );
}
rs.close();
stmt.close();
}
catch(Exception e){
System.out.println(e);
}
JTable table = new JTable(data, columnNames);
TableColumn col;
for (int i = 0; i < table.getColumnCount(); i++) {
col = table.getColumnModel().getColumn(i);
col.setMaxWidth(250);
}
JScrollPane scrollPane = new JScrollPane( table );
p.add( scrollPane );
JFrame f=new JFrame();
f.add(p);
f.setSize(600,400);
f.setVisible(true);
}
}

Thanks









Related Tutorials/Questions & Answers:
creation of table using a Java swing
creation of table using a Java swing  how to create a table dynamically in Java swing
Table Creation
Table Creation  hi! I want a table which looks like following can u tell me how it can be made with java swings.. YEAR 2005 Jan Feb... to make such table? plz help.........  
Advertisements
Table Creation
Table Creation  create the table for the following fields.its very urgent for me.plz help me S.No,Category( From the home page),Name of the Candidate( After registering and after selecting the category),Age,Title of the project
Insert into table using Java Swing
INSERTION IN TABLE USING SWING In this section, We will insert rows into "Mysql" database using "Swing". What is Swing? Swing... than Awt component. Swing can be used to build Standalone GUI Application
website creation using java and mysql - Java Beginners
website creation using java and mysql  i am going to create a website for some company using java and mySql... i dont know the procedure to create a website.can anybody give me the steps what i have to follow
Cache creation using java - Java Beginners
Cache creation using java  Hi All, I am developing a web application, I have a plan to use cache in that application. I used jsp caching with the help of jsp taglib. But I want to write code in a java class,not in the jsp
Query on Java Swing - Table Cell Issue - Swing AWT
Query on Java Swing - Table Cell Issue  Hi, I have a query on Java Swing. we are using swing in our application, In one of the frame we are using JTable which has 6 columns which are editable. When I use the TAB button from
Using swing - Java Beginners
Using swing  How can one use inheritance and polymophism while developing GUI of this question. Develop an application that allows a student to open an account. The account may be a savings account or a current account
Database Table Creation Example with JDBC Batch
Database Table Creation Example with JDBC Batch: In this example, we are discuss about table creation in the database using JDBC Batch process. First...("Database Table Creation Sucessfully.");        // connection committed
Jar file creation - Swing AWT
Jar file creation  i have developed a swing application using Net beans IDE..i am also using 3 rd party JAR files... my application is a serail port... this? 2. To run a java swing application what are the necesseray things the clients
jar File creation - Swing AWT
jar File creation  I am creating my swing applications. How can i... in java but we can create executable file in java through .jar file.. how can i convert my java file to jar file? Help me
creation button using objective c
creation button using objective c  creation button using objective c
how to create a header in jtable using java swing
how to create a header in jtable using java swing  how to create a header in jtable using java swing   d
creation of drop down menu using ajax in java - Ajax
creation of drop down menu using ajax in java  Hi, Here I want to create a drop down menu using ajax in ofbiz framework. I want to fetch the data from database.I got examples using asp.net and php but I am not getting
How to Hide Button using Java Swing
Programming application how to hide the buttons using Java Swing. Please Visit this below reference link http://www.roseindia.net/tutorial/java/swing...How to Hide Button using Java Swing  Hi, I just begin to learn java
forums creation using spring with hibernate?
forums creation using spring with hibernate?  how to write mandatory fields with validations in forms using spring with hibernate? give me detailed example
Import object in Excel using java swing
Import object in Excel using java swing  Hi sir, I want to make a swing application where I can import a object by clicking a button. I am using... in 'Insert' ribbon. first select a cell (cell no will be inside java code) then go
Navigate Data using Java Swing
Navigate Data using Java Swing In this java tutorial section, you will learn how to navigate the Database data using Java Swing. For this, we have created a form with four buttons to perform an action. Through these buttons, we have
Adding checkbox in table using that delete table rows
the selected rows using swing in java...Adding checkbox in table using that delete table rows  I need coding for how to add checkbox in table,the table data from database.Using
Creation and insertion in table
CREATION OF  TABLE,INSERTION &DISPLAY OF DATA  USING SQL QUERY   In this progam we create table in MYSQL using "create" statement and insert data using "insert " statement query
compareing images using java - Swing AWT
compareing images using java  hi can u please give me the code in java to compare imges..i have the program to get the pixel values using pixel... with another image,i.e,program to compare two images using the pixel values.. thank
How To Display MS Access Table into Swing JTable - Java Beginners
How To Display MS Access Table into Swing JTable  How to Display...){ System.out.println(e); } JTable table = new JTable(data, columnNames); TableColumn... JScrollPane( table ); p.add( scrollPane ); JFrame f=new JFrame(); f.add(p
How to create Multiple Frames using Java Swing
Multiple Frames in Java Swing In this section, you will learn how to create multiple frames. Java Swing provides the utility to show frame within another frame by providing the class JInternalFrame. With the use of this class, you can
Java swing
to the database using java swing...Java swing  I create one table. That table contains task ID and Task Name. When I click the task ID one more table will be open and that table
create, edit ,open simple documents using java - Swing AWT
want to use Java Swing or JSP? Do you want to create word document file...create, edit ,open simple documents using java   In my program I have a text area.How to create document which will contain text in text
Reading .doc file using swing
Reading .doc file using swing  Sir, Could U Please Tell me the Way To Read .doc file in java using swing,with code
jtable with table headers - Swing AWT
jtable with table headers  give me java code to create jtable with table headers and by which i can scroll jtable and can retrieve height and width of the table
creation of installer - Java Magazine
creation of installer  plz tell me how can be create installer for any developed application in java?  visit the following url izpack.org.. it will helps u
java swing
java swing  view the book details using swing
Lost Using Swing Components
Lost Using Swing Components  Hello, I sound like every other newbie but I desperately need help. I have to write an application for the WebBuy Company that allows a user to compose the three parts of a complete email message
Lost Using Swing Components
Lost Using Swing Components  Hello, I sound like every other newbie but I desperately need help. I have to write an application for the WebBuy Company that allows a user to compose the three parts of a complete email message
Lost Using Swing Components
Lost Using Swing Components  Hello, I sound like every other newbie but I desperately need help. I have to write an application for the WebBuy Company that allows a user to compose the three parts of a complete email message
How to export the table content from an webpage to excel using java?
How to export the table content from an webpage to excel using java?  How to export the table content from an webpage to excel using java? The table contents are generated dynamically in that java page
How to export the table content from an webpage to excel using java?
How to export the table content from an webpage to excel using java?  How to export the table content from an webpage to excel using java? The table contents are generated dynamically in that java page
xml file creation in java
xml file creation in java  how to create xml file in java so...; Please visit the following links: http://www.roseindia.net/tutorial/java/xml...;Please visit the following links: http://www.roseindia.net/tutorial/java/xml
how to move records from one table to other based on its creation time
how to move records from one table to other based on its creation time ... to second table based on the record creation time means the records should not be present in first table after creation of two days,and it has to move
creation an dmanipulation of trees - Java Beginners
/java/example/java/swing/index.shtml Thanks...creation an dmanipulation of trees  Hi guys? pls i want to find... a Binary Search Tree -To use the Java API's Stack in conjunction with other
create , edit MS WORD like document file using Java Swing - Swing AWT
? I am using Java SWING. Plz. email your answer...create , edit MS WORD like document file using Java Swing   In my...://www.roseindia.net/tutorial/java/poi/readDocFile.html Thanks
object creation - Java Beginners
object creation  I need object creation in depth(with stack,pc registers).Any one can provide me if possible with video/audio
java - Swing AWT
java  i need to set the popup calender button in table column&also set the date in the same table column using core java-swing
steps to create desktop application in java swing using eclipse with drag and drop options
steps to create desktop application in java swing using eclipse with drag and drop options  please help to create desktop application in java swing using eclipse with drag and drop and what are the plugins required
java swing
java swing  add two integer variables and display the sum of them using java swing
how to update values of a html form into an excel table using java servlets?
how to update values of a html form into an excel table using java servlets?  i have written a java servlet program, which has a html form... be loaded into an excel table automatically. i have created a dsn for excel
how to load values of html form into an excel table using java servlet?
how to load values of html form into an excel table using java servlet?   i have written a java servlet program, which has a html form to be filled... be loaded into an excel table automatically. i have created a dsn for excel table
give me source code of webpage creation using html
give me source code of webpage creation using html  how to create a webpage using html
xml creation in java
xml creation in java  HI, I need a java program to create an xml file... therez a tutorial in your site to create an xml file at http://www.roseindia.net/xml/dom/CreatXMLFile.shtmlADS_TO_REPLACE_1 but this isn't creating
Using poi hwpf,how to create table in word document. - Java Beginners
Using poi hwpf,how to create table in word document.  Can you please tell me how to create a table in the word document in java using Apache poi hwpf.its very urgent.Please send some sample code.Thanks in advance
java swing - Swing AWT
java swing  how i can insert multiple cive me exampleolumn and row in one JList in swing?plz g  Hi Friend, Please clarify your question. Thanks
how to convert doc file into html using java swing
how to convert doc file into html using java swing  i want to convert doc file into html and display it on jtextarea please help me and give the sample code
virtual onscreen keyboard project using java and swings - Swing AWT
virtual onscreen keyboard project using java and swings  sir thanks a lot for ur reply for my last question, can u please send me the entire project code of virtual on screen keyboard.i did but im not sure as it was right

Ads