Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 25th, 2008, 03:25 AM
Newbie
 
Join Date: Nov 2008
Posts: 8
Default Adding a scrollbar to a JScrollPane

I'm trying to add a verticle scroll bar to my scrollPane so it can go up and down the list as needed what sort of lines do I need to add to get this to work.

Expand|Select|Wrap|Line Numbers
  1.    private void refreshScrollPane(int panel)
  2.    {
  3.        if(panel == 1)
  4.        {
  5.            directoryPanelA.remove(scrollPane1);
  6.            invalidate();
  7.            scrollPane1 = new JScrollPane(directoryAList);
  8.            directoryPanelA.add(scrollPane1);
  9.        }
  10.        if(panel == 2)
  11.        {
  12.            directoryPanelB.remove(scrollPane2);
  13.            invalidate();
  14.            scrollPane2 = new JScrollPane(directoryBList);
  15.            directoryPanelB.add(scrollPane2);
  16.        }
  17.    }
Reply
  #2  
Old November 25th, 2008, 07:03 AM
JosAH's Avatar
Moderator
 
Join Date: Mar 2007
Location: Voorschoten, the Netherlands
Age: 52
Posts: 8,760
Default

My guess is that you're abusing a JScrollPane, i.e. that thing already implements scrollbars, either when needed or always visibile. I don't think I understand your question.

kind regards,

Jos
Reply
  #3  
Old November 25th, 2008, 05:11 PM
Newbie
 
Join Date: Nov 2008
Posts: 8
Default

I'm not sure what you do not understand here. I'll try and be a little more specific (not used to typing out my questions I guess). Ok so I have a scrollpane which holds a JList.. this code refreshes the scroll pane removes the scrollPane component adds the list to it then re-adds the scrollPane to the component. I want it to have a scroll bar on the right hand side that is verticle that allows me to scroll through the jlist that's in the scrollpane. Wow I hope that explained it a little more haha thanks.

Expand|Select|Wrap|Line Numbers
  1.    private void refreshScrollPane(int panel)
  2.    {
  3.        if(panel == 1)
  4.        {
  5.            directoryPanelA.remove(scrollPane1);
  6.            invalidate();
  7.            scrollPane1 = new JScrollPane(directoryAList);
  8.            directoryPanelA.add(scrollPane1);
  9.        }
  10.        if(panel == 2)
  11.        {
  12.            directoryPanelB.remove(scrollPane2);
  13.            invalidate();
  14.            scrollPane2 = new JScrollPane(directoryBList);
  15.            directoryPanelB.add(scrollPane2);
  16.        }
  17.    }
Reply
  #4  
Old November 25th, 2008, 05:22 PM
JosAH's Avatar
Moderator
 
Join Date: Mar 2007
Location: Voorschoten, the Netherlands
Age: 52
Posts: 8,760
Default

Quote:
Originally Posted by chanshaw View Post
I'm not sure what you do not understand here. I'll try and be a little more specific (not used to typing out my questions I guess). Ok so I have a scrollpane which holds a JList.. this code refreshes the scroll pane removes the scrollPane component adds the list to it then re-adds the scrollPane to the component. I want it to have a scroll bar on the right hand side that is verticle that allows me to scroll through the jlist that's in the scrollpane. Wow I hope that explained it a little more haha thanks.
Again, you don't have to take care of that; just add your JList to a JScrollPane, add that pane to, say, the content panel of a JFrame and you're in business. The JScrollPane takes care of those scroll bars.

kind regards,

Jos
Reply
  #5  
Old November 25th, 2008, 06:44 PM
Newbie
 
Join Date: Nov 2008
Posts: 8
Default

Ok perfect, thanks for the information.
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.