• Post Reply Bookmark Topic Watch Topic
  • New Topic

JScrollPane overlapping with JTabbedPane

 
Bill Clar
Ranch Hand
Posts: 163
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been googling from one end of the internet to the other, and it appears I have a problem with nested scrollable elements.

I can't create an SSCCE due to the amount of code and data, particularly images, required. What I can provide is a screenshot:



I have a JTabbedPane (BorderLayout.WEST) on the left which contains a JScrollPane (scrollbars as needed) in each tab. On the right is the JScrollPane (BorderLayout.EAST) that provides thumbnail images. As I scroll down the images, it creates the hiccup above.

I tried adding both to a JPanel(new FlowLayout()), then adding that to BorderLayout.CENTER. Nada. It displays the JTabbedPane, but not the JScrollPane.

I appreciate any advice or links you can offer.

~Bill


 
Bill Clar
Ranch Hand
Posts: 163
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I managed to whittle down a SSCCE.

 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to do with scrollable elements and everything to do with how BorderLayout lays out the WEST and EAST components. Yes, they can overlap, with the first added component appearing on top.

Here's a SSCCE to demonstrate that:
Since this isn't the behavior you desire, you need to choose an appropriate layout manager. Not BorderLayout.
 
Bill Clar
Ranch Hand
Posts: 163
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gah! That's freaky. Thank you, Darryl!
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+1 but another of reasons for JFrame.pack()
 
Bill Clar
Ranch Hand
Posts: 163
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFrame.pack()? I tried that and the overlap went away but it enlarged the width of my GUI. Strange. It's like the JTable wants a width of 400, when it only needs 200.

Well, that's an easier problem to fix than overlap. Whew!
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill Clar wrote:Gah! That's freaky. Thank you, Darryl!

You're welcome. And I wouldn't call it freaky. It's just BorderLayout doing what it's designed to do.

You'll read in many places that only one component can be added to each region of a BorderLayout. That too is not true; BorderLayout manages the last component added to each region. Any components added earlier are usually not visible since their bounds default to [0, 0, 0, 0]. SSCCE:For your layout requirement, I think I would opt to use a JSplitPane.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!