When one decides to use a JScrollPanel because the object to display (a JPanel containing a GroupLayout, in my case) is taller than the high of the container (a JPanel tabPanel1 of a JTabbedPane, in my case), while the width of this JPanel object is thinner than the width of the container, one obtains ...
- the vertical scrolling rail (right side of the tabPanel1) without the horizontal scrolling rail (underneath)
- the JPanel positionned at the left side of the tabPanel1
By means of a GridBagLayout, I try to place the JPanel in the horizontal center of the tabPanel1 :But I get this way a wrong effect:
- tabPanel1 comes as wanted in the horizontal center of the tabpanel (surronunded by a thin line, as not wanted).
- The two scrolling rails disappear. When I reduce the main frame to recover one of both of them, the tabPanel1 disappears completely ! Namely when I try to reduce the main frame the slightest bit under the initial width or high of the tabbedPane, by means ofIf I don't implement this 'setPreferredSize()', at the initial display, the GUI is larger than the screen, because of the natural dimension of one of the other 'tabPanel's, and I loose the scrolling rails too.
In other words, how to make coexisting 1) a tabbedPane with a 'setPreferredSize()' and 2) a JPanel containing a GridBagLayout, itself containing at its horizontal center a JScrollPane (, itself containing a GroupLayout()).
Thanks in advance to those who try to help me.
Snorry for my bad English.
Unless I've misunderstood your requirements, this works for me.
Charles Van Damme
Joined: Feb 24, 2009
Good day, everybody.
Dear Darryl Burke,
Thanks for your good example; my problem is solved.
The point was : How to have my page content be centered (horizontally) in my JTabbedPane = main frame, with provision of a JScrollPane, when this tabPane is wider than my page content ?
The answer is :
- Use a first JPanel (scrollPanel) to embed my Layout and the whole page content.
- Use a second JPanel (scrollHolder) to hold the JScrollPane (!) and embed the scrollPane.
- Then tabPane.addTab(tabPaneTitle, new JScrollPane(scrollHolder));
My mistake : I was using a single JPanel - equiv. to 'scrollPane' - embedding the large GroupLayout, which was an object of a separated class extending JScrollPanel.
And I was usinginstead of
I seems as if the JPanel scrollHolder in ' scrollHolder.add(scrollPanel); ' does offer the "wanted centering service", and the single JPanel in my previous implementation not. But why ? Can a conflict situation arise between the GroupLayout and the JScrollPane features ? I don't think so.