7 Replies - 2559 Views - Last Post: 15 November 2012 - 02:18 PM Rate Topic: -----

#1 hwoarang69  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 171
  • Joined: 23-October 12

Scrollpane not working

Posted 12 November 2012 - 07:31 AM

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.

Is This A Good Question/Topic? 0
  • +

Replies To: Scrollpane not working

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Scrollpane not working

Posted 12 November 2012 - 10:36 AM

A JComponent can only be at one place at the same time

        // yopu put l_list inside sp here
        JScrollPane sp = new JScrollPane(l_list,

        // but
        p.add(l_list);  // this removes l_list from sp and put it in the JPanel
        p.add(sp);      // this put the now empty JSCrollPane in the Panel



:^:/>

This post has been edited by pbl: 12 November 2012 - 11:26 AM

Was This Post Helpful? 0
  • +
  • -

#3 hwoarang69  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 171
  • Joined: 23-October 12

Re: Scrollpane not working

Posted 12 November 2012 - 02:11 PM

omg thank alot. got it to working now :)
Was This Post Helpful? 0
  • +
  • -

#4 tony12095  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 109
  • Joined: 23-October 12

Re: Scrollpane not working

Posted 12 November 2012 - 02:58 PM

You just have to remember that when you add a scroll pane, you use that as your component because if you use the inside component, in your case, a JList, it wont add the scroll pane.
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Scrollpane not working

Posted 12 November 2012 - 07:48 PM

View Posttony12095, on 12 November 2012 - 05:58 PM, said:

You just have to remember that when you add a scroll pane, you use that as your component because if you use the inside component, in your case, a JList, it wont add the scroll pane.

Thanks, it wasn't clear at all in my mind
Was This Post Helpful? 0
  • +
  • -

#6 tony12095  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 109
  • Joined: 23-October 12

Re: Scrollpane not working

Posted 13 November 2012 - 06:08 AM

View Postpbl, on 13 November 2012 - 02:48 AM, said:

View Posttony12095, on 12 November 2012 - 05:58 PM, said:

You just have to remember that when you add a scroll pane, you use that as your component because if you use the inside component, in your case, a JList, it wont add the scroll pane.

Thanks, it wasn't clear at all in my mind



No problem :) thats why we're all here, to help each other. :^:
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Scrollpane not working

Posted 13 November 2012 - 08:16 AM

I was sarcastic :v:
Was This Post Helpful? 0
  • +
  • -

#8 tony12095  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 109
  • Joined: 23-October 12

Re: Scrollpane not working

Posted 15 November 2012 - 02:18 PM

oh, well sarcasm gets nowhere. B)/> But i was actually writing that to hwoarang69 when i wrote the post...

This post has been edited by tony12095: 15 November 2012 - 02:19 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1