Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

JScroll not working with JList

Thread view: 
kodonne2 - 08 Jan 2004 19:25 GMT
this is someone elses post - but I'm having the same problem with my GUI  and can't figure it out. No body responded to his post so I'll try again, please help!:

I've put a JList in a JScrollPane:

    addLinks1List = new JList();
    addLinks1Pane = new JScrollPane();

        addLinks1Pane.setViewportView(addLinks1List);

The ScrollPane is in a GridBagLayout

The list is filled and orientation is VERTICAL. When my JList gets
bigger than the viewport, no ScrollBar appears, even when I state that a
vertical scrollbar should appear, it is never scrollable.
The data is in the list, I am sure of that.

Does anyone know why my List never becomes Scrollable?
ak - 08 Jan 2004 19:26 GMT
short example?

--

____________

http://reader.imagero.com the best java image reader.
kodonne2 - 08 Jan 2004 20:52 GMT
There is a short example below - I added all of my properties too for each - just in case something I'm doing in JList is nullifing what I'm doing in JScrollPane or vice versa?  Thanks in advance for any help!

JList jList1;
JScrollPane scrollPane = new JScrollPane(jList1);  
listItems.add(..)    

jList1 = new JList(listItems);

scrollPane.setBounds(38,117,120,114);
scrollPane.setAutoscrolls(true);
scrollPane.createVerticalScrollBar();
scrollPane.setWheelScrollingEnabled(true);
scrollPane.setNextFocusableComponent(jList1);
scrollPane.setEnabled(true);
jList1.setEnabled(true);
jList1.setAutoscrolls(true);
jList1.setDebugGraphicsOptions(0);
jList1.setDoubleBuffered(false);
jList1.setNextFocusableComponent(scrollPane);
jList1.setRequestFocusEnabled(true);
jList1.setFixedCellHeight(-1);
jList1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jList1.setBounds(new Rectangle(0, 0, 104, 114));

this.getContentPane().add(scrollPane, null);
scrollPane.add(jList1);
ak - 09 Jan 2004 17:38 GMT
you have here many things which are unnecessary:

> scrollPane.setBounds(38,117,120,114);
this is job of LayoutManager

> scrollPane.createVerticalScrollBar();
no need at all (used by ScrollPaneUI implementations to create the vertical
scrollbar - you should override it if you want JScrollPane to use some
subclass of JScrollBar)

> scrollPane.setNextFocusableComponent(jList1);
???

> scrollPane.setEnabled(true);
enabled by default

> jList1.setEnabled(true);

enabled by default

> jList1.setDebugGraphicsOptions(0);
javadoc says: A value of 0 causes no changes to the debugging options.

> jList1.setDoubleBuffered(false);
why?

> jList1.setNextFocusableComponent(scrollPane);
???

> jList1.setRequestFocusEnabled(true);
this is default value

> jList1.setFixedCellHeight(-1);
this is default value

> jList1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
this is default

> jList1.setBounds(new Rectangle(0, 0, 104, 114));
this  is job of JScrollPane's LayoutManager

--

____________

http://reader.imagero.com the best java image reader.
kodonne2 - 08 Jan 2004 20:52 GMT
There is a short example below - I added all of my properties too for each - just in case something I'm doing in JList is nullifing what I'm doing in JScrollPane or vice versa?  Thanks in advance for any help!

JList jList1;
JScrollPane scrollPane = new JScrollPane(jList1);  
listItems.add(..)    

jList1 = new JList(listItems);

scrollPane.setBounds(38,117,120,114);
scrollPane.setAutoscrolls(true);
scrollPane.createVerticalScrollBar();
scrollPane.setWheelScrollingEnabled(true);
scrollPane.setNextFocusableComponent(jList1);
scrollPane.setEnabled(true);
jList1.setEnabled(true);
jList1.setAutoscrolls(true);
jList1.setDebugGraphicsOptions(0);
jList1.setDoubleBuffered(false);
jList1.setNextFocusableComponent(scrollPane);
jList1.setRequestFocusEnabled(true);
jList1.setFixedCellHeight(-1);
jList1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jList1.setBounds(new Rectangle(0, 0, 104, 114));

this.getContentPane().add(scrollPane, null);
scrollPane.add(jList1);
xarax - 09 Jan 2004 16:05 GMT
> There is a short example below - I added all of my properties too for each - just in case something I'm doing in JList is nullifing what I'm doing in
JScrollPane or vice versa?  Thanks in advance for any help!

> JList jList1;
> JScrollPane scrollPane = new JScrollPane(jList1);
[quoted text clipped - 3 lines]
>
> scrollPane.setBounds(38,117,120,114);

You don't need these:
> scrollPane.setAutoscrolls(true);
> scrollPane.createVerticalScrollBar();
> scrollPane.setWheelScrollingEnabled(true);
> scrollPane.setNextFocusableComponent(jList1);
> scrollPane.setEnabled(true);

> jList1.setEnabled(true);
> jList1.setAutoscrolls(true);

Forget these:
> jList1.setDebugGraphicsOptions(0);
> jList1.setDoubleBuffered(false);
> jList1.setNextFocusableComponent(scrollPane);
> jList1.setRequestFocusEnabled(true);

> jList1.setFixedCellHeight(-1);
> jList1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
> jList1.setBounds(new Rectangle(0, 0, 104, 114));

Don't know what LayoutManager you're using...
> this.getContentPane().add(scrollPane, null);

> scrollPane.add(jList1);

Don't use JScrollPane.add(). Use JScrollPane.setViewportView() instead.

Read the Swing JavaDoc.
kodonne2 - 08 Jan 2004 21:46 GMT
Okay - I've finally got it!  

I took off the scrollBar.add(jList1) at the bottom and made sure that I didn't have more than one declaration of scrollBar.  I also didn't define scrollBar until after I added the list to jList1.

if anyone else is having the same problem - e-mail me at the address used in my first post and I can help (this took me so long to figure out that I don't anyone to have to spend this much time if I can help out).

KO


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.