Hi I have got one example in
http://forum.java.sun.com/thread.jspa?threadID=5166643&tstart=105 link
and i modified it, it is working fine.
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
public class TableRowColumn extends JFrame
{
JTable table;
DefaultTableModel model;
JPanel buttonPanel;
JButton button;
public TableRowColumn()
{
// Create table
Object[][] data =
{
{new Integer(1), "A"},
{new Integer(2), "B"},
{new Integer(3), "C"}
};
String[] columnNames = {"Number","Letter"};
model = new DefaultTableModel(data, columnNames);
table = new JTable(model)
{
public boolean isCellEditable(int row, int column)
{
return true;
}
};
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
table.getColumnModel().getColumn(0).
setCellRenderer( table.getDefaultRenderer(Integer.class) );
// Add table and a Button panel to the frame
final JScrollPane scrollPane = new JScrollPane( table );
getContentPane().add( scrollPane, BorderLayout.CENTER );
buttonPanel = new JPanel();
getContentPane().add( buttonPanel, BorderLayout.SOUTH );
button = new JButton( "Add" );
button.setMnemonic('A');
buttonPanel.add( button );
button.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out,println("In the Add action");
}
});
button = new JButton( "Update" );
buttonPanel.add( button );
button.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out,println("In the Update action");
}
});
button = new JButton( "Delete" );
buttonPanel.add( button );
button.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out,println("In the Delete action"); }
});
}
public static void main(String[] args)
{
TableRowColumn frame = new TableRowColumn();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible(true);
}
}
But the same thing i want to implement in my application, i am getting the window with the rows, but I am not able to select anything, or click any of the buttons.
In my application i have one text field and search button, after entering the test, and clicking the serach button, I should get this window with rows, and i should be able to select, and do the operations.
I have commented the main function in the above class.
Then i have created an instance of the class in the actionPerformed() of the search button, then i did the following things in the actionPerformed() of the search button.
TableRowColumn frame = new TableRowColumn();
frame.pack();
frame.setVisible(true);
I am not able to select any row, and i am not able to click the buttons.
Please suggest me what to do now.
Regards,
Sri.