ScrollPane?
can anyone help me please?
how do I get the ScrollPane on the JList?
I ve tried to do this:
JScrollPane scr = new JScrollPane(list);
orderBillPanel.add(scr);
but it does not work. Why?
What am I doing wrong?
Thanks.
import javax.swing.UIManager;
import java.awt.*;
public class GuiPointOfSaleClass {
boolean packFrame = false;
/**Construct the application*/
public GuiPointOfSaleClass() {
Frame1 frame = new Frame1();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
/**Main method*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new GuiPointOfSaleClass();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class Frame1 extends JFrame {
JPanel contentPane;
JPanel orderBillPanel = new JPanel();
JList list;
DefaultListModel listModel;
Border border1;
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
border1 = BorderFactory.createEtchedBorder(Color.white,new Color(165, 163, 151));
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.setTitle("PointOfSale");
this.setSize(new Dimension(1100, 800));
orderBillPanel.setBounds(new Rectangle(11, 138, 293, 406));
orderBillPanel.setLayout(null);
listModel = new DefaultListModel();
//Create the list and put it in a scroll pane.
list = new JList(listModel);
list.setBackground(Color.yellow);
list.setFont(new java.awt.Font("Dialog", 0, 14));
list.setBounds(new Rectangle(11, 8, 377, 418));
contentPane.add(orderBillPanel, null);
orderBillPanel.add(list);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectedIndex(0);
list.setVisibleRowCount(50);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new GuiPointOfSaleClass();
}
}

