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



Home Answers Viewqa Framework creation of table using a Java swing

Have Programming Question? Ask it here!
 
 
 


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


how to create a table dynamically in Java swing?


Advertisement
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
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
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
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
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
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 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
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
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
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
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
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
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
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
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
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
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
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
java swing
java swing  add two integer variables and display the sum of them using java swing
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
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
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
are displayed in the table..I need the source code in java swing...Java swing  If i am login to open my account the textfield,textarea and button are displayed. if i am entering the time of the textfield
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
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
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 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
Java swing
Java swing  what are the root classes of all classes in swing
Java swing
Java swing  Does Swing contains any heavy weight component
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
java swing
java swing  what is java swing   Swing is a principal GUI toolkit for the Java programming language. It is a part of the JFC (Java Foundation Classes), which is an API for providing a graphical user interface for Java
java swing
java swing  how to connect database with in grid view in java swing   Hi Friend, Please visit the following link: Grid view in java swing Thanks
java swing - Swing AWT
java swing  how to add image in JPanel in Swing?  Hi Friend, Try the following code: import java.awt.*; import java.awt.image....: http://www.roseindia.net/java/example/java/swing/ Thanks
Java swing
Java swing  Write a java swing program to calculate the age from given date of birth
java swing - Swing AWT
java swing   how i can insert in JFrame in swing?  Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; class FormDemo extends JFrame { JButton ADD; JPanel
java swing - Swing AWT
java swing   Iam developing a java web browser.Actually my code works fine ie. i can load a web page without proxy.But in my place i have only proxy... a proxy or how to make my java web browser to listen to proxy setting??? please help
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
 

 

 

DMCA.com