1

In a project I'm doing I have a set of JTextPane's wrapped in JPanels inside a JFrame. The JTextPane's can be various sizes when the programming is actually running, and what size they will be cannot be predicted, unless it is hardcoded. To make sure that all of the JTextPane's (which are inside the JPanels) are viewable, I have put everything in a scroll pane. Here's the catch: I want the JTextPane's to extend past the bottom of the JScrollPane if needed, but I don't want them to extend past the side. I also want the JPanels/JTextPanes to take up as much space as possible horizontal, without requiring the use of a horizontal scroll bar. This means that if the window is resized horizontally, the JTextPanes need to resize to fill the horizontal space. The JTextPanes are wrapped first in a panel that uses the "GroupLayout" supplied with the Netbeans GUI builder, and then in a panel that uses a BoxLayout. The reason it is BoxLayout is that I add new elements (JTextPane's wrapped in a panel), to it via code. It is much easier to do this using BoxLayout.

I tried setting the prefferred width of the JTextPane's to Integer.MAX_VALUE, but that just caused them to extend out of site to the right. I then tried disabling, the horizontal scrollbar, but the JTextPanes still extended to the right. Now I couldn't even scroll to see them! Finally I tried using an event to catch whenever the JFrame resized, then I would call methods to cause everything in the tree to resize. But this didn't seem to work at all. I did this by trying to set the preferred width of each JTextPane to the preferred width of the JFrame, but it didn't seem to have any effect.

Here's what it looks like if I have the width of the inner JTextPane set to 427: enter image description here

Here's what I have if I leave the JTextPane's size at "Default" (which I believe is Integer.MAX_VALUE): enter image description here

In case it matters, I'm using the Netbeans GUI builder (Matisse), so I'd prefer a solution that didn't involve changing the layout manager, but I would be open to that. Note that as I said above, the BoxLayout is used in some of the panels, it's actually part of the issue.

DonyorM
  • 1,760
  • 1
  • 20
  • 34
  • can you provide some screenshots? A picture tells a thousand words – Oliver Watkins Oct 09 '14 at 11:24
  • Maybe you need to use a GridBagLayout on your panel and make sure that the text panes use the horizontal fill constraint. If you need more help then post a [SSCCE](http://sscce.org/) that demonstrates the problem. – camickr Oct 09 '14 at 15:00
  • @OliverWatkins I've added screenshots. I'm working on an SSCCE – DonyorM Oct 10 '14 at 10:27

0 Answers0