public class J_01_FLOW_08 extends JApplet 
{
    JPanel p = new JPanel();//nedd a jpanel to add scroll
        String s_value[] = {"black","red","pink","yellow","blue","orange"};
        DefaultListModel dlm = new DefaultListModel();
        JList l_list = new JList(dlm);
        JScrollPane sp = new JScrollPane(l_list,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    JLabel l_label = new JLabel();


    Container c;
    FlowLayout flow = new FlowLayout();


    public void init()
    {
        c = getContentPane();
        c.setLayout(flow);

        for(String sv: s_value) //add all list in dlm
        {
            dlm.addElement(sv);
        }
        l_list.setVisibleRowCount(4);

        l_list.setFixedCellHeight(30);
        l_list.setFixedCellWidth(150);
        l_list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); //selected as maany as you can

        p.add(l_list);
        p.add(sp);
        p.add(l_label);
        c.add(p);

    }
}

for some reason its not print the scroll bar.

Can you add the needed import statements so the code will compile and also post the html needed to execute the applet so the code can be compiled and tested?

I think you need to set jscrollpane's size first

imports:

import java.awt.*;
import javax.*;

i tried putting
sp.setSize(34,34);

but still no luck.

i can see the list. but there is no scrollpane

why are you adding l_list to jscrolpane, and then adding l_list to p, and then again adding the jscrollpane to p?

oh lol got it to working now. i was add l_list two times. i had to remove p.(l_list);

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.