Total members 11889 |It is currently Fri Mar 29, 2024 12:36 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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




Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

Sorry i don't have any idea about it as i am also a beginner and is in learning phase



Author:
Newbie
User avatar Posts: 18
Have thanks: 0 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.. :)



Author:
Newbie
User avatar Posts: 27
Have thanks: 1 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);

    }
}

 



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Thanks for sharing such nice information.



Author:
Newbie
User avatar Posts: 4
Have thanks: 0 time
Post new topic Reply to topic  [ 5 posts ] 

  Related Posts  to : database contents display in table format in swing
 HTML Table Of Contents Generator     -  
 Display data from database as Tree Structure in JSP     -  
 need help building table in my database!     -  
 Delete data from database table in php     -  
 List Database, Table, and Field in php     -  
 Listing the Contents of a Directory     -  
 get the Contents of a ZIP File in java     -  
 PDF Format     -  
 Format Specifier in C     -  
 What is Swing?!!     -  



Topic Tags

Java Swing
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com