0

enter image description here

I have a file with a JScrollBar and a JPanel inside with boxlayout.

In another file I have a JPanel (also BoxLayout) with a JList inside (without JScrollPane - only the list). The list can grow as much as it needs.

The problem is when I add the 2nd file in the first file JPanel, it just does not resize to fit the content. The JList is just cutted like the next image.

enter image description here

What can I do to fix it?

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
rtmc
  • 109
  • 1
  • 7
  • 1
    1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) Provide ASCII art of the GUI as it should appear in smallest size and (if resizable) with extra width/height. – Andrew Thompson Oct 28 '13 at 04:45
  • I have only the netbeans project, I'll try to make it clean. – rtmc Oct 28 '13 at 06:03
  • Ok, I think I solved it already. Thanks to answer of this question: http://stackoverflow.com/questions/8815401/how-do-i-recalculate-preferred-size-of-a-jcomponent I've used component.setPreferredSize(null); to recalculate the preferredSize of the jList and all of its parents at the 2nd file. It was enough for me. – rtmc Oct 28 '13 at 06:42
  • `used component.setPreferredSize(null);` Ah yes. Twice a day, three times on some days, we get questions here where ***not*** doing that is the solution. Glad you got it sorted. :) You should consider now either deleting the question, or entering your own answer. – Andrew Thompson Oct 28 '13 at 06:48
  • I can only answer after 8 hours. I will post the answer later because I did not find anything similar on net, it might be helpfull for someone. Thanks! – rtmc Oct 28 '13 at 06:50
  • By the way it seems to me that you are mixing up `JScrollBar` and `JScrollPane` in your question. – Holger Oct 28 '13 at 10:44
  • Yeah, sorry, the image says "bar", but it should be pane! – rtmc Oct 28 '13 at 19:06

1 Answers1

0

[posting as an answer]

Ok, I think I solved it already.

Thanks to answer of this question: How do i recalculate preferred size of a JComponent?

I've used

component.setPreferredSize(null);

to recalculate the preferredSize of the jList and all of its parents at the 2nd file. It was enough to solve for me.

Community
  • 1
  • 1
rtmc
  • 109
  • 1
  • 7