I am trying to make a scrolling Jlist like
http://www.java2s.com/Code/Java/Swing-JFC/AsimpleJScrollPaneforaJListcomponent.htm, but that example is a frame with one panel. I have a Jlist within "panel", which is within "tabSection", which is within my frame. How do i use the "getContentPane()"? The problem is on the last statement in this code.
Code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class RecipeTab extends JPanel
{
private JList list;
private DefaultListModel listModel;
private JTextField employeeName;
private JScrollPane scrollPane;
public RecipeTab(JFrame frame, TabSection tabSection, JPanel panel)
{
String categories[] = { "Household", "Office", "Extended Family",
"Company (US)", "Company (World)", "Team", "Will",
"Birthday Card List", "High School", "Country", "Continent",
"Planet","Household", "Office", "Extended Family",
"Company (US)", "Company (World)", "Team", "Will",
"Birthday Card List", "High School", "Country", "Continent",
"Planet","Household", "Office", "Extended Family",
"Company (US)", "Company (World)", "Team", "Will",
"Birthday Card List", "High School", "Country", "Continent",
"Planet","Household", "Office", "Extended Family",
"Company (US)", "Company (World)", "Team", "Will",
"Birthday Card List", "High School", "Country", "Continent",
"Planet" };
list = new JList(categories);
scrollPane = new JScrollPane(list);
list.setPreferredSize(new Dimension(tabSection.getWidth(), tabSection.getHeight()));
panel.add(list);
//problem here doesnt compile, but I need this line to get scrolling
getContentPane().add(scrollpane, BorderLayout.CENTER);
}
}
Thanks for the help. I am very rusty with all this

Edit: Sorry the spacing copied over horribly
This post was edited by xandumx on May 24 2012 10:59pm