0
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.

Edited by Dani: Formatting fixed

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by hwoarang69
1

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?

0

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

1

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

0

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

thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.