473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.    }
Nov 25 '08 #1
4 3770
JosAH
11,448 Expert 8TB
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
Nov 25 '08 #2
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.    }
Nov 25 '08 #3
JosAH
11,448 Expert 8TB
@chanshaw
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
Nov 25 '08 #4
Ok perfect, thanks for the information.
Nov 25 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: porky008 | last post by:
I need to add a search button to this and have no clue how to do it. Can some one please help me on this? import java.awt.*; import java.awt.event.*; import javax.swing.*; import...
1
by: 123456prakash | last post by:
Does anyone know if it is possible to set programmatically the position of a JScrollPane vertical scrollbar slider? I load a some components like textfield editorpane labels etc into a panel...
0
by: madumm | last post by:
Hi all; How can i set a Background Image to this JScrollPane? JLabel imageLabel; JScrollPane jsp = new JScrollPane(imageLabel); Pls need your sugessions... Thanking in advance Madumm
10
by: dudeishfish | last post by:
Hey Everyone! After using Devshed (possibly the worst forum I have ever encountered) I have come here with my questions and answers about Java, Python, VB, Basic C++, HTML, Game Maker, and...
2
by: blackraven1425 | last post by:
It displays the information off the left of the screen instead of in a line. Any ideas? I'll post the code here too. I know it returns nothing at the moment, it's a work in progress. public...
1
by: sumancal | last post by:
I have Jlist , and i am using HORIZONTAL WRAP , and now want a VerticalscrollBar when needed. i am giving you the my sample of code public void reinitialize() { removeAll(); ...
1
TheMan1
by: TheMan1 | last post by:
Hi guys. I have a mouse event on my frame that enlarges the size of a JPanel that in on a JScrollPane. When the JPanel's size changes, the JScrollPane's scrollbars don't "refresh" ie. their max...
1
by: raylopez99 | last post by:
Scrollbars scroll bars adding scrollbars in C# Forms 2.0 scrollbars don't work won't work how to add scrollbar in C# Here is how to add a scrollbar to a form. It's not in any book. For future...
6
BSCode266
by: BSCode266 | last post by:
Hey everyone, I'll cut right to the case. I have a JPanel and i call setLayout(null) on it. Simply because I would like to position everything myself and haven't seen a handy manager yet. Now i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.