Note that there are some explanatory texts on larger screens.

plurals
  1. POadding a JList to a table and adding the table to a scroll pane
    text
    copied!<p>I have created a JList and I want to add it to the table and then add the table to the scroll pane so that both of them will be contained in the scroll pane.</p> <pre><code>import model.*; import java.awt. *; import java.text.*; import javax.swing.*; import javax.swing.table.TableColumn; public class ScrollPanel extends JPanel implements View { private Prison prison; private String[] cells = new String[20]; private JList list = new JList(cells); public ScrollPanel(Prison prison) { this.prison = prison; prison.attach(this); setup(); build(prison); } public void setup() { } public void build(Prison prison) { int rows = 20; int columns = 2; for (int i = 0; i &lt; 20; i++) { cells[i] = prison.cells().get(i).id(); } JTable table = new JTable(rows, columns); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableColumn column = null; column = table.getColumnModel().getColumn(0); column.setPreferredWidth(91); column = table.getColumnModel().getColumn(1); column.setPreferredWidth(91); table.add(list); JScrollPane scrollPane = new JScrollPane(table); scrollPane.setPreferredSize(new Dimension(220, 150)); add(scrollPane); } public void update() { } } </code></pre> <p>This is how my program looks when I did the code I pasted above, which is adding the list to the table. <a href="http://img21.imageshack.us/img21/3237/11834317.jpg" rel="nofollow noreferrer">alt text http://img21.imageshack.us/img21/3237/11834317.jpg</a> When I added the table to the list and then to the scroll pane, this is how it looked. How do I add them both to the scroll pane with both of them showing?</p> <p><a href="http://img27.imageshack.us/img27/3678/94687555.jpg" rel="nofollow noreferrer">alt text http://img27.imageshack.us/img27/3678/94687555.jpg</a> </p> <p>This is what it should look like..</p> <p><a href="http://img21.imageshack.us/img21/1343/90528093.jpg" rel="nofollow noreferrer">alt text http://img21.imageshack.us/img21/1343/90528093.jpg</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload