Question: creation of table using a Java swing

Ads

 
 
 

Share on Google+Share on Google+

Swasthi.S.Bhat
creation of table using a Java swing
1 Answer(s)      6 years and 6 months ago
Posted in : Framework

how to create a table dynamically in Java swing?

Ads
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


Ads









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
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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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.shtml but this isn't creating a file, its just
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
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
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
java swing
java swing  view the book details using swing
cache creation in java - Java Beginners
cache creation in java  Hi All, I am planing to create cache in my web application. please send me the some sample code to create cache by using org.apache.oro.utils package. please help me out. Thanks, mln15584
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
PDF creation in JAVA - JSP-Servlet
PDF creation in JAVA  HI! Good morning.... I want to create pdf file and i want to write something into pdf file....before creation. Upto creation i have done but how to write data into pdf. File Writer is not working
Tutorials   
Java Spring Hibernate Struts Training Spring 3 MVC Login Form Example Spring 3 MVC Login Form Example Error with LogIn with mysql database Selenium webdriver - Getting Xpath for element in IE Selenium webdriver - Getting Xpath for element in IE springframework Industrial problem maths Groovy Editor using Eclipse RCP Plugin Development Selenium-HP-Alm framework containment how to implement Single Sign On in enterprise application using spring framework Deploy war file Hadoop Mapreduce Java spring 15/03/14 How to found which class or method contain specific annotation? com.pixelmed.dicom.DicomException: No reader for jpeg-lossless available What is Software development framework? pie chart Struts 2 is it necessary to have depth knowledge on servlets jsp and jdbc to learn java frameworks Spring MVC and Hibernate with DWR 3 -- Configuration Using MySQL Database Spring Validations project web programming web programming is it possible to display page in full frame...after dividing page into frames...and is it possible to close frame write code in c# in an application one task has to done for every 15 minutes ? How con you do it? What is the structure of Spring framework? Scheduler triggering cron jobs multiple times at the scheduled time and job is retained even after deleting How to align the select tags in a single column. struts 1.3 array matrix i got illegal start of expression error , plese tell me the mistake where i did... zend2 frame work Spring Login Page Error not able to deploy application war on JBOSS 6.0 running on linux 5.5 URL Regular Expression for Struts Validator URL Regular Expression for Struts Validator getOutputStream() has already been called for this response how to develope a struts application using hibernate? Dialling from computer with other phone via modem card ORACLE- ATG -E Commerce ORACLE- ATG -E Commerce struts need of frameworks in java? need of frameworks in java? need of frameworks in java?

Ads

 
Advertisement null

Ads