473,465 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Adding a scrollbar to a JScrollPane

67 New Member
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 3771
JosAH
11,448 Recognized Expert MVP
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
chanshaw
67 New Member
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 Recognized Expert MVP
@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
chanshaw
67 New Member
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.