For example:
public class ListTest extends JPanel{
private JTable table;
private String COLUMN1 = "COLUMN1";
private JTextArea myTA;
public ListTest() {
table = new JTable(new Object[][]{{"1"}, {"2"}}, new Object[]{COLUMN1});
TableColumn col = table.getColumn(COLUMN1);
col.setIdentifier(COLUMN1);
col.setHeaderValue("Data");
table.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
@Override
public void valueChanged(ListSelectionEvent e){
if (!e.getValueIsAdjusting()){
int selRow = table.getSelectedRow();
final Object data = selRow >= 0 ? table.getModel().getValueAt(selRow, 0) : null;
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
if (data != null){
myTA.setText(data.toString());
}
else{
myTA.setText("");
}
}
});
}
}
});
setLayout(new BorderLayout());
JScrollPane scroll = new JScrollPane(table);
scroll.setPreferredSize(new Dimension(50, 200));
add(scroll, BorderLayout.WEST);
add(new JScrollPane(myTA = new JTextArea()), BorderLayout.CENTER);
}
public static void main(String[] args){
JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ListTest listTest = new ListTest();
// Add content to the window.
frame.add(listTest);
// Display the window.
frame.pack();
frame.setSize(400, 200);
frame.setVisible(true);
}
}
An advice: read the excellent Using Swing Components tutorial, there are the responses to almost every basic question and a lot of examples.