+1  A: 

What do you want to achieve by adding a JList to a table? It's a fundamentally wrong thing to do - JTables aren't intended to have components added to them at all. If you want the table to display the items in the list, you need an implementation of the TableModel interface, not a JList.

Edit: If you want the JList and the JTable to be displayed next to each other, you have to addthem both to a JPanel before adding that to the ScrollPane. But this is a rather unusualy thing to do; normally, a table is in a ScrollPane of its own. You could have a separate ScrollPane each for the table and the list. Or you could simply put the list items in the first column of the table. Which is better depends on your requirements.

Michael Borgwardt
so if I use TableModel and add the table model and JList to the scroll, they will come together?
Karen
+1  A: 

I'm not sure what you are trying to achieve, if you just want to have the first column in the table show values for a row id like 1.1,1.2,1.3, etc, you could just add those to the first column of the jtable, you could even style that column different w/ Renderers. If that will not work then you could try and set the JList on the rowHeader of the scrollpane, similiar to the below. You will need to adjust the row height to accomodate the list height, or vice-versa. But this will achieve what you want and allow the list to scroll w/ the table. Good Luck!

import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JScrollPane; import javax.swing.JTable;

public class Scroll {

public static final void main(String[] args){
 JFrame f = new JFrame();
 f.setSize(new Dimension(400,400));
 JList list = new JList(new Object[]{"1.1","1.2","1.3","1.4","1.5","1.6","1.7","1.8","1.9","1.10","1.11"});
 JTable table = new JTable(11,10);
 JScrollPane sp = new JScrollPane(table);
 sp.setRowHeaderView(list);
 f.getContentPane().add(sp);
 f.setVisible(true);
}

}

broschb
I need a JList so that when I click on a number, a panel will pop up showing the details of that prison cell.
Karen
You can do that with a table. Based on these requirements I would implement as above, but I think a cleaner approach would be to do this in a table, you could render the first cell different to show it is clickable, or has an action associated with it. You can add a columnModelListener, or a ListSelectionListener to the table. These events will allow you to listen to various events on the table that should allow you to achieve what you want.table.getSelectionModel().addListSelectionListener('YOUR LISTENER')table.getColumnModel().addColumnModelListener('YOUR LISTENER')
broschb
A: 

Maybe you could add a "Details" button to each row of the table. If, so then the TableButtonColumn will help you out.

camickr