I fixed the StackOverFlowError problem from my last thread.. however, my ActionListener is still not working. if any GUI guru here may point out the issue, it would be great. i think this is something very simple and i miss it.
//my ActionListener class
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ShowTable implements ActionListener
{
private DataHolder dh = new DataHolder();
private JScrollPane sPane;
private JTable sTable;
public ShowTable(JScrollPane paraS, JTable paraT)
{
this.sPane = paraS;
this.sTable = paraT;
}
public void actionPerformed(ActionEvent e)
{
try
{
sTable = new JTable(dh.getRowData(), dh.getColumnNames());
sTable.setAutoCreateRowSorter(true);
sTable.setBackground(java.awt.Color.lightGray);
}
catch(SQLException sqle)
{
sqle.printStackTrace();
}
sPane = new JScrollPane(sTable);
}
}
And this is my Menu class, please see the middle *** section
you may ignore the rest of the code in the class, the GUI itself works
import java.text.MessageFormat;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
public class MenuBar extends JPanel
{
private FlowLayout fl = new FlowLayout();
private JMenuBar menuBar;
private JMenu menuFile, menuEdit;
public JMenuItem openMenuItem, closeMenuItem, printMenuItem, showTableMItem, addRecordMItem;
private JScrollPane scrollPane;
private JTable table;
public MenuBar()
{
openMenuItem = new JMenuItem("Open");
openMenuItem.setHorizontalTextPosition(SwingConstants.LEFT);
openMenuItem.setAccelerator(KeyStroke.getKeyStroke('o', java.awt.Event.CTRL_MASK, false));
//openMenuItem.addActionListener(new ActionPerform(i));
closeMenuItem = new JMenuItem("Close");
closeMenuItem.setAccelerator(KeyStroke.getKeyStroke('q', java.awt.Event.CTRL_MASK, false));
closeMenuItem.addActionListener(new closeMenuHandler());
printMenuItem = new JMenuItem("Print");
printMenuItem.setAccelerator(KeyStroke.getKeyStroke('p', java.awt.Event.CTRL_MASK, false));
////////////// ACTION ///////////////////////
//////////// Menu Bar Edit items /////////////////
showTableMItem = new JMenuItem("Show Table");
******** this is the problem *********************
showTableMItem.addActionListener(new ShowTable(scrollPane, table));
******* please ignore the rest of the code **********
addRecordMItem = new JMenuItem("Add Record");
//addRecordMItem.addActionListener(this);
///////////////////////////////////////////////
///////////////// MENU Config ///////////////////////////////////////
menuFile = new JMenu("File");
menuFile.add(openMenuItem);
menuFile.add(printMenuItem);
menuFile.add(closeMenuItem);
menuEdit= new JMenu("Edit");
menuEdit.add(showTableMItem);
menuEdit.add(addRecordMItem);
///////////////////////////////////////
//////// Add all menu things to the menu bar /////////
menuBar = new JMenuBar();
menuBar.add(menuFile);
menuBar.add(menuEdit);
setLayout(fl);
fl.setAlignment(FlowLayout.LEFT);
add(menuBar);
}// end Constructor
}// end class MenuBar
class closeMenuHandler implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
}