January 07, 2012

how to create dynamic table in java

How to create a dynamic table in java

Description : The example show how to create a dynamic table using java swing, The code is developed using eclipse ide

/** DyanmicJTable
*
* version 1.0
*Aaron+Rodgers
*
*/
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JTextField;
import java.awt.GridBagLayout;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import java.awt.GridBagConstraints;
import java.util.Vector;
/**
*
*/
/**
* @author vishnu
*
*/
public class DyanmicJTable extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
private JTextField jTextField = null;
private JPanel jPanel = null;
private JScrollPane jScrollPane = null;
private JTable jTable = null;
private DefaultTableModel tableModel = null;
/**
* This is the default constructor
*/
public DyanmicJTable() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(600, 600);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJTextField(), null);
jContentPane.add(getJPanel(), null);
}
return jContentPane;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(218, 50, 176, 23));
jButton.setText("Add to table");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Vector rowData = new Vector();
rowData.add(jTextField.getText());
tableModel.addRow(rowData);
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return jButton;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(30, 49, 170, 26));
}
return jTextField;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.gridy = 0;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.gridx = 0;
jPanel = new JPanel();
jPanel.setLayout(new GridBagLayout());
jPanel.setBounds(new Rectangle(22, 105, 524, 214));
jPanel.add(getJScrollPane(), gridBagConstraints);
}
return jPanel;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJTable());
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
tableModel = new DefaultTableModel();
tableModel.addColumn("Name");
String [] data = {"jhon duke"};
tableModel.addRow(data);
jTable = new JTable(tableModel);
}
return jTable;
}

public static void main(String[] args) {
    DyanmicJTable dynamicTable = new DyanmicJTable();
    dynamicTable.setVisible(true);
    dynamicTable.setDefaultCloseOperation(EXIT_ON_CLOSE);
}

}

Description : Creating dynamic table (Grid) in java web application using javascript



Example

One Indian Girl by chetan bhagat

Java swing dynamic table example

create a dynamic table

18 comments:

  1. What a funny blog! I truly enjoyed watching this humorous video with my relatives as well as
    with my mates.

    Feel free to surf to my site: Recommended Internet site

    ReplyDelete
  2. What's up to all, as I am truly keen of reading this weblogís post to be updated on a regular basis. It contains good material.

    Feel free to visit my web-site; linked website

    ReplyDelete
  3. You will find the most updated news being uploaded or published in blogs and celeb news sites.
    You can give tips to the workers in the salon, restaurants where the star visit frequently.
    As a consequence it can be contended the media
    is directing many persons astray moving away from
    what should be its aim of presenting discerning news and analytic thinking
    of pressing topics for this celebrity frippery.

    Feel free to surf to my web site; loverespectloyalty.com

    ReplyDelete
  4. " Forum Threads " Blog Comments " Corporate Blogging " Social Network Profiles
    " Link Baiting. Also, find one that has includes videos explaining the latest news because that is sometimes the best way to see it. Every now and then, new stars emerge and disappear in the blink of an eye and every smallest detail about the same becomes important celebrity news.

    Here is my website latest celeb news

    ReplyDelete
  5. Thus, there are many broad options for getting to know various kinds of news today and that too through the use of
    various mediums. We realize that we don't need to listen to outside authorities; we are not guided by our internal authority. I want to mention a part of the Prime Law (Twelve Visions Party) which is part of Neothink.

    Also visit my web-site; international news

    ReplyDelete
  6. This valuable text is invaluable. When can one read more?


    Also visit my web page; fitness tips men

    ReplyDelete
  7. It's truly very complicated in this active life to listen news on TV, therefore I just use world wide web for that reason, and get the hottest news.

    Also visit my weblog; click through the next site

    ReplyDelete
  8. AnonymousMay 23, 2013

    The агtіcle offers proven bеneficіal to us.
    Ιt’s reаlly іnfoгmative and yοu're simply obviously really knowledgeable of this type. You have got opened up my own sight to different opinion of this kind of subject using intriguing, notable and reliable content material.

    My site ... Cialis Online

    ReplyDelete
  9. AnonymousJune 25, 2013

    This is my first time pay a quick visit at here and i am really impressed to read all at alone
    place.

    My web blog - iphone and ipad

    ReplyDelete
  10. AnonymousJuly 01, 2013

    Hi friends, how is the whole thing, and what you desire to say about this paragraph, in my view its truly awesome designed for me.


    Stop by my homepage :: whatsapp on laptop

    ReplyDelete
  11. AnonymousJuly 15, 2013

    This comment has been removed by a blog administrator.

    ReplyDelete
  12. These are truly great ideas in regarding blogging.
    You have touched some pleasant points here. Any way keep up wrinting.


    Feel free to visit my weblog ... download kik messenger

    ReplyDelete
  13. Howdy very cool site!! Man .. Beautiful .
    . Wonderful .. I will bookmark your web site and take the feeds also?

    I'm happy to search out a lot of helpful information here in the put up, we'd like develop extra techniques in this regard, thank you for sharing.

    . . . . .

    my web page - übersetzung disturbed meaning of life

    ReplyDelete
  14. I am regular visitor, how are you everybody? This paragraph posted at
    this site is in fact fastidious.

    Take a look at my webpage: elektro laubsauger test

    ReplyDelete
  15. Hello, i think that i saw you visited my
    website so i got here to go back the desire?.I am trying to
    to find things to enhance my web site!I guess its good enough to make use of some of your ideas!!

    ReplyDelete
  16. Awesome blog! Is your theme custom made or did you download it from somewhere?

    A design like yours with a few simple tweeks would really make my blog shine.
    Please let me know where you got your design.
    Many thanks

    my web site; mp3 player sport (n.ethz.ch)

    ReplyDelete
  17. This is a unusual looking cooking lid is made of soft silicone.
    There are different gestures for different moments, moods and each gesture is unique in its own way.

    The TV crew will embark on the task of helping "sweet" businesses survive and prosper.


    My page cannon's cake and candy supplies, ,

    ReplyDelete
  18. It's really a cool and useful piece of info. I am glad
    that you shared this helpful info with us. Please stay us
    up to date like this. Thanks for sharing.

    Look at my website; Preisvergleich Laubsauger

    ReplyDelete

Your feedback may help others !!!

Facebook comments