?
Solved

JScrollPane doesn't work on a JList?

Posted on 2003-04-01
14
Medium Priority
?
595 Views
Last Modified: 2012-06-27
It should, but I'm not getting it to..

I have subclassed the JList in order to make it fit into my BoxLayout.
therefore I have

CustomJList myJList = new CustomJList();

to enable JScrollPane..
JScrollPane myScroll = new JScrollPane(myJList);

I don't see scrollbars though! I have enough information to make the JList scroll but the scrollbar just simply wouldn't appear.

0
Comment
Question by:kinklaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +2
14 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8245299
JScrollPane myScroll = new JScrollPane(myJList, VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_ALWAYS);

will show the scrollbars always, whether needed or not

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8245303
JScrollPane myScroll = new JScrollPane(myJList, VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_ALWAYS);

should be

JScrollPane myScroll = new JScrollPane(myJList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

0
 

Author Comment

by:kinklaz
ID: 8245310
thanks CEHJ, but your code doesn't seem correct..
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:kinklaz
ID: 8245312
ok wait..
0
 

Author Comment

by:kinklaz
ID: 8245316
nope, doesn't work :(
0
 
LVL 9

Accepted Solution

by:
Ovi earned 60 total points
ID: 8245930
"I have subclassed the JList in order to make it fit into my BoxLayout" - if you have overriden the method getPreferredSize() to achive your desired behaviour, you can kiss good bye your scrollPane :).
0
 

Author Comment

by:kinklaz
ID: 8246347
aah let me try..
0
 
LVL 3

Expert Comment

by:msterjev
ID: 8248220
You should never use setPreferredSize()if you want to use JScrollPane(). The Ovi is correct!
0
 
LVL 92

Expert Comment

by:objects
ID: 8249830
> I have subclassed the JList in order to make it fit into my BoxLayout

why exactly??

> if you have overriden the method getPreferredSize() to
> achive your desired behaviour, you can kiss good bye your scrollPane

Not necessarily. This may be related to the problem, but just because getPreferredSize() is overriden doesn't mean you won't get scroll bars.

If overriding getPreferredSize() was the reason for subclassing, then this is the wrong approach as it is in fact the scroll pane that is being added to the box layout managed container and it's /min/max/preferred sizes that are used for layout.
Instead set the required sizes on your scroll pane:

JList myJList = new JList();
JScrollPane myScroll = new JScrollPane(myJList);
myScroll.setPreferredSize(..
myScroll.setMinimumSize(..
myScroll.setMaximumSize(..



0
 
LVL 9

Expert Comment

by:Ovi
ID: 8251293
1. "Not necessarily. This may be related to the problem, but just because getPreferredSize() is overriden doesn't mean you won't get scroll bars."

2. "If overriding getPreferredSize() was the reason for subclassing, then this is the wrong approach as it is in fact the scroll pane that is being added to the box layout managed container and it's /min/max/preferred sizes that are used for layout."

A little confusion here, don't you think 'objects'?  I see that finally you agree that getPreferredSize() is the wrong alternative, but the solution from my experience is not to set the size of the component to fit into something (only when it is absolutely necesary), generaly also a wrong alternative, but work with the LayoutManager constraints for achieve the desired effect. That's the scope of the layout, to lay down the managed components in a specific way, described by the layout itself.

kinklaz: So, if you cannot achieve the desired GUI design by using your BoxLayout you should switch to other layout manager, which is capable of representing the components in a way closer to yours. You should not change the default behaviour of your components. If ypu need assistance, you can post a little description of components used and how to lay them out.
0
 
LVL 92

Expert Comment

by:objects
ID: 8251319
> A little confusion here, don't you think 'objects'?  

Not really :)

> but the solution from my experience is not to set the size of the component to fit into something

There has been no mention of setting the size of anything.
That is what the layout managers job is.


0
 

Author Comment

by:kinklaz
ID: 8263467
sorry for being late..
I think the problem here is me using the BoxLayout.
Ovi's got a very good comment here..
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8263484
*Did* you override getPreferredSize?
0
 

Author Comment

by:kinklaz
ID: 8263685
yes..
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question