This is what i have attempted:
CODE
import java.awt.*; //the importing of required libraries
import java.io.*;
import java.awt.event.KeyListener;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.table.*;
import javax.swing.event.*;
public class UpdateEventMain extends JDialog
{
private JPanel contentPane; //declaring variables
private JLabel titleMain;
private JPanel pnlTop;
private JPanel pnlCenter;
private JPanel pnlBottom;
private JButton btnUpdate;
private JButton btnExit;
JTable table;
Vector rows,columns;
DefaultTableModel tabModel;
JScrollPane scrollPane;
public UpdateEventMain() {
super();
initializeComponent();
}
private void initializeComponent() {
contentPane = (JPanel)this.getContentPane();
pnlTop = new JPanel(); //declaring JPanels
pnlCenter = new JPanel();
pnlBottom = new JPanel();
btnUpdate = new JButton();
btnExit = new JButton();
titleMain = new JLabel("UPDATE EVENTS"); //setting text, font and colour
titleMain.setFont(titleMain.getFont().deriveFont(Font.BOLD, 48));
titleMain.setForeground(Color.black);
contentPane.setLayout(new BorderLayout(5, 5)); //adding my JPanels to content pane using a border layout
contentPane.add(pnlTop, BorderLayout.NORTH);
contentPane.add(pnlCenter, BorderLayout.CENTER);
contentPane.add(pnlBottom, BorderLayout.SOUTH);
contentPane.setBackground(new Color(0, 0, 0));
pnlTop.setLayout(new FlowLayout()); //setting my JPanels with a flow layout
pnlTop.add(titleMain, 0); //adding a variable
rows= new Vector();
columns= new Vector();
String[] columnNames =
{
"Position",
"First Name",
"Last Name",
"Event",
"Time",
};
addColumns(columnNames);
tabModel=new DefaultTableModel();
tabModel.setDataVector(rows,columns);
table = new JTable(tabModel);
scrollPane= new JScrollPane(table);//ScrollPane
table.setRowSelectionAllowed(false);
//table.getModel().addTableModelListener(this);
pnlCenter.add(scrollPane);
btnUpdate.setText(" UPDATE RECORDS ");
btnUpdate.addActionListener(new ActionListener() { //adding an action listener to the button
public void actionPerformed(ActionEvent e)
{
btnUpdate_actionPerformed(); //calling up the buttons action event
}
});
btnExit.setText(" EXIT ");
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
btnExit_actionPerformed();
}
});
pnlBottom.setLayout(new FlowLayout(FlowLayout.CENTER, 6, 5));
pnlBottom.add(btnUpdate, 0);
pnlBottom.add(btnExit, 1);
setSize(800, 608);
setTitle("Update");
setResizable(false); //so users cant resize the JDialog
setVisible(true);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); //action if dialog is closed
}
private void btnUpdate_actionPerformed()
{
}
private void btnExit_actionPerformed()
{
this.dispose(); //exit
}
public void addColumns(String[] colName)//Table Columns
{
for(int i=0;i<colName.length;i++)
columns.addElement((String) colName[i]);
}
public void addRow() //Add Row
{
Vector r=new Vector();
r=createBlankElement();
rows.addElement(r);
table.addNotify();
}
public Vector createBlankElement()
{
Vector t = new Vector();
t.addElement((String) " ");
t.addElement((String) " ");
t.addElement((String) " ");
t.addElement((String) " ");
t.addElement((String) " ");
return t;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new UpdateEventMain(); //run this class and make it visible
}
});
}
}
I am getting a table in the correct panel, but there are no cells in the table. I am a bit lost now.