Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying Records in Table  RSS feed

 
sri rallapalli
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I am new to swing.
I have one requirement, I have to display some set of records(dinamically) in a table and at the end of displaying all the records, i should have 3 buttons, for editing, deleting and adding. I should also be able to select the records in the table then if i click the button, then i need to do the corresponding actions. Please help me in developing such window.

thanks,
Sri.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
start here

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

and if you still need help, post the specific problem, along with the code you've tried
 
sri rallapalli
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sri rallapalli
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Just in addition to the previous explanation, if i close the serach window, then i am able to do the operations on the new pop-up JTable window, i just want to know, what should i do, to do the operations on the pop-up JTable even though the search window is in open state.

regards,
Sri.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!