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);
}
What a funny blog! I truly enjoyed watching this humorous video with my relatives as well as
ReplyDeletewith my mates.
Feel free to surf to my site: Recommended Internet site
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.
ReplyDeleteFeel free to visit my web-site; linked website
You will find the most updated news being uploaded or published in blogs and celeb news sites.
ReplyDeleteYou 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
" Forum Threads " Blog Comments " Corporate Blogging " Social Network Profiles
ReplyDelete" 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
Thus, there are many broad options for getting to know various kinds of news today and that too through the use of
ReplyDeletevarious 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
This valuable text is invaluable. When can one read more?
ReplyDeleteAlso visit my web page; fitness tips men
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.
ReplyDeleteAlso visit my weblog; click through the next site
The агtіcle offers proven bеneficіal to us.
ReplyDeleteΙ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
This is my first time pay a quick visit at here and i am really impressed to read all at alone
ReplyDeleteplace.
My web blog - iphone and ipad
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.
ReplyDeleteStop by my homepage :: whatsapp on laptop
This comment has been removed by a blog administrator.
ReplyDeleteThese are truly great ideas in regarding blogging.
ReplyDeleteYou have touched some pleasant points here. Any way keep up wrinting.
Feel free to visit my weblog ... download kik messenger
Howdy very cool site!! Man .. Beautiful .
ReplyDelete. 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
I am regular visitor, how are you everybody? This paragraph posted at
ReplyDeletethis site is in fact fastidious.
Take a look at my webpage: elektro laubsauger test
Hello, i think that i saw you visited my
ReplyDeletewebsite 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!!
Awesome blog! Is your theme custom made or did you download it from somewhere?
ReplyDeleteA 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)
This is a unusual looking cooking lid is made of soft silicone.
ReplyDeleteThere 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, ,
It's really a cool and useful piece of info. I am glad
ReplyDeletethat you shared this helpful info with us. Please stay us
up to date like this. Thanks for sharing.
Look at my website; Preisvergleich Laubsauger