Total members 9952 | Gratitudes |It is currently Sat Feb 11, 2012 2:54 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 5 posts ] 
Author Code Snippet
 Code subject: database contents display in table format in swing
PostPosted: Sun Mar 29, 2009 2:58 pm 
Offline
Newbie
User avatar

Joined: Sun Mar 29, 2009 2:49 pm
Posts: 1
Has thanked: 0 time
Have thanks: 0 time

i want to fetch data from database and want to show fetched datas in jtable in swing...

can anyone give me some sample code about this


TOP
 Profile Send private message  
Reply with quote  
 Code subject: Re: database contents display in table format in swing
PostPosted: Mon Apr 20, 2009 1:29 pm 
Offline
Newbie
User avatar

Joined: Sat Apr 18, 2009 1:20 pm
Posts: 20
Location: UK
Has thanked: 0 time
Have thanks: 0 time
Sorry i don't have any idea about it as i am also a beginner and is in learning phase

_________________
Lincoln Solicitors


TOP
 Profile Send private message  
Reply with quote  
 Code subject: Re: database contents display in table format in swing
PostPosted: Wed Sep 22, 2010 12:59 pm 
Offline
Newbie
User avatar

Joined: Tue Sep 07, 2010 9:18 am
Posts: 30
Has thanked: 0 time
Have thanks: 1 time
sorry i also dont know about this....
Even i am confuse how it will work??????
If anyone know plz reply as soon as possible.. :)

_________________
Robinetterie industrielle


TOP
 Profile Send private message  
Reply with quote  
 Code subject: Re: database contents display in table format in swing
PostPosted: Thu Oct 27, 2011 12:00 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 57 time
Example for using jtable to show data ,
Code:


import java
.awt.Color;
import java.awt.Dimension;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;

 
public class 
TableExample extends JTable {

    private static 
TableExample dataTable null;
    private static 
Vector<StringcolsNames;

    private 
TableExample() {
    }

    private 
TableExample(Object[] headersObject[][] rows) {

        
super(rowsheaders);
        
setShowGrid(true);
        
setAutoscrolls(true);
        
setSize(800600);
        
setColumnSelectionAllowed(true);
        
JTableHeader header getTableHeader();
        
header.setBackground(Color.BLUE);
        
SetColsWidth(this);
        
Dimension dim = new Dimension(201);
        
setIntercellSpacing(new Dimension(dim));
        
SetRowHight(this);
        
setAutoResizeMode(AUTO_RESIZE_OFF);
        
setModel(dataModel);
    }

    public static 
TableExample getInstance() {
        if (
dataTable == null) {
            
dataTable.createDatatableCols();
            
dataTable = new TableExample();

        }

        return 
dataTable;
    }

    public static 
TableExample getInstance(Object[] headersObject[][] rows) {
        if (
dataTable == null) {
            
dataTable.createDatatableCols();
            
dataTable = new TableExample(headersrows);

        }

        return 
dataTable;
    }

    public final static 
void createDatatableCols() {
        
colsNames = new Vector<String>();
        
colsNames.add("column name1");
        
colsNames.add("column name2");
        
colsNames.add("column name3");


        
colsNames.add("column name4");
        
colsNames.add("column name5");
        
colsNames.add("column name6");
        
colsNames.add("column name7");
        
colsNames.add("column name8");
        
//Class

        
colsNames.add("column name9");
        
colsNames.add("column name10");
        
colsNames.add("column name11");
        
colsNames.add("column name12");
        
colsNames.add("column name13");

        
colsNames.add("column name14");

    }

    public 
void updateDataModel(Vector<VectoriReservations) {

        
System.out.println("Cols number" colsNames.size());
        
System.out.println("Rows number" iReservations.size());

        
TableModel tableModel = new DefaultTableModel(iReservationscolsNames);

        
setModel(tableModel);
    }

    public 
void SetRowHight(JTable table) {
        
int height table.getRowHeight();
        
table.setRowHeight(height 10);
    }

    public 
void SetColsWidth(JTable table) {
        
TableColumnModel columnModel table.getColumnModel();
        
int width 100;
        
columnModel.setColumnMargin(10);

    }
}

 

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Code subject: Re: database contents display in table format in swing
PostPosted: Wed Jan 18, 2012 8:48 am 
Offline
Newbie
User avatar

Joined: Tue Jan 17, 2012 8:35 am
Posts: 4
Has thanked: 0 time
Have thanks: 0 time
Thanks for sharing such nice information.


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 5 posts ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 Need to Display Content using JavaScript in HTML page  Scripting Language  stankov  0
 Creating table using div tag  HTML examples  msi_333  0
 put caption at the bottom of table  HTML examples  msi_333  0
 adding caption to table in html  HTML examples  msi_333  0
 database connection  Java  katanor  1

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team