> Help,
>
> I'm trying to add a JScrollPane to the JFrame contentPane.
I can see you're tring..
> ...But its not
> limiting the size of the whole windows despite my various calls to
> (setBounds, setMaximumSize, setViewSize, setSize) limit the size.
This probably boils down to layouts and..
>..It
> seems once the JScrollPane is added to the JFrame, the window
> immediately takes up the WHOLE SCREEN SIZE even though I set the max to
> 640x480. It seems to ignore my sizing limitations. Why is swing so
> difficult to do something easy?
Swing is not a 'paint by magic' x-plat GUI designer, you
need to understand how to use and apply layouts.
> ..I feel stupid.
>
> mainFrame = new JFrame( this );
What's 'this'?
> mainFrame.pack();
Always good when called at the right point, which this is not.
> mainFrame.setBounds( 200, 200, 640, 480 );
> mainFrame.setVisible( true );
>
> JScrollPane jsp = new JScrollPane(tabPane);
> mainFrame.pack();
Always good when called at the right point, which this is not.
Hey.. dejavu! Why are you calling pack() twice?
> mainFrame.getContentPane().add( jsp );
> mainFrame.pack();
'ditto'
> jsp.setBounds( 200, 200, 640, 480 );
> jsp.setMaximumSize(new Dimension(640,480));
> jsp.getViewport().setViewSize(new Dimension(540,380));
> jsp.getViewport().setSize(new Dimension(540,380));
> mainFrame.pack();
..sigh. Just how many times do you call pack() throughout
this code? No ..don't tell me, becasue I suspect the problem
lies somewhere between 'this' and 'tabPane'.
Let the (short, complete) code do the talking..
<http://www.physci.org/codes/sscce.jsp>

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Presented In DOUBLE VISION Where Drunk
Ok its because of the tabPane contained in the JScrollPane is using
GridLayout where one of the columns is huge. Anyway, if the
JScrollPane is what contains the TabPane (which contains JPanels), why
is it that the ScrollPane max size doesn't override whatever size of
its children? You mean I have to set the max size on all children?
Help
Andrew Thompson - 20 Jul 2005 21:20 GMT
> You mean I have to set the max size on all children?
No, I mean it is very hard to know what you are doing when my
crystal ball is missing and you fail to supply code.
(Again) <http://www.physci.org/codes/sscce.jsp>
> Help
Please try not to sound pathetic.

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
It's Like "Hee Haw" With Lasers
mingclee1@gmail.com - 20 Jul 2005 23:15 GMT
Hi, by just looking at your code, the reason that JScrollPane takes the
entire frame is because JFrame uses BorderLayout by default. If you
add to JFrame with with only one component and didn't specify location
(center, south..) it will default to center and occupy the whole frame.
You can check BorderLayout for more detail.
To achieve what you want try to set layout manager to null on the
JFrame.
Andrew Thompson - 20 Jul 2005 23:42 GMT
> To achieve what you want try to set layout manager to null on the
> JFrame.
That is a very poor way to 'fix' (almost) any layout problem.
Please do not give layout advice until you have more experience.

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Transmitido en Martian en SAP
mingclee1@gmail.com - 21 Jul 2005 00:46 GMT
I know what you are saying. A novice Swing programmer should always
stick to some kind of layout manager. But given the problem, wouldn't
the solution I give solve it? How would you have solved it then?
Andrew Thompson - 21 Jul 2005 01:23 GMT
> I know what you are saying. A novice Swing programmer should always
> stick to some kind of layout manager. But given the problem, wouldn't
> the solution I give solve it?
What 'it'? We do not know what the tabPane is or does,
what constraints of visibility it must posess, or what other
elements the OP intends to add to the GUI to achieve what end
effect. All we have so far is some code snippets and vague
descriptions.
>...How would you have solved it then?
That is yet to be seen, since the OP has not yet replied to..
>> (Again) <http://www.physci.org/codes/sscce.jsp>
So, to put that another way. I would solve it by..
1) Finding out what the OP is attempting to do, rather
than take random guesses at it.
2) Suggesting further tutorials, layouts, strategies as
appropriate.

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Controlling You Through A Chip In Your Butt Since 1999
Michael Rauscher - 22 Jul 2005 10:19 GMT
mingclee1@gmail.com schrieb:
> I know what you are saying. A novice Swing programmer should always
> stick to some kind of layout manager. But given the problem, wouldn't
> the solution I give solve it? How would you have solved it then?
Perhaps by using a layout manager that takes care of the components
maximum size?
E.g. Swing's BoxLayout, JGoodies' FormsLayout...
Bye
Michael
Monique Y. Mudama - 22 Jul 2005 15:29 GMT
> I know what you are saying. A novice Swing programmer should always
> stick to some kind of layout manager. But given the problem,
> wouldn't the solution I give solve it? How would you have solved it
> then?
I don't consider myself an expert Swing programmer, but your statement
seems to imply that skilled Swing programmers might choose not to use
a layout manager. This doesn't sound right to me. I would imagine
that if they couldn't find a layout manager with the right
characteristics, they'd simply write one themselves.
Call to those who consider themselves to be quite knowledgeable and
experienced with Swing: do you ever choose to use a null layout
manager?

Signature
monique
Andrew Thompson - 24 Jul 2005 12:39 GMT
>> I know what you are saying. A novice Swing programmer should always
>> stick to some kind of layout manager. But given the problem,
[quoted text clipped - 10 lines]
> experienced with Swing: do you ever choose to use a null layout
> manager?
That depends on what you mean by "quite knowledgeable
and experienced" and "expert". *
I answer a lot of Swing questions, but do not consider myself
'quite knowledgeable' though I am 'experienced'. I am not an
'expert' on anything. (shrugs)
But for my part. Yes and no.
1) Yes I would write my own layout manager. and
2) *no* - a null Layout is no manager. As soon as it is,
as soon as you add the slightest bit of logic to the widget
placement, you might as well add that logic to a separate
class and call it a layout manager, just so it is encapsulated.
* ..actually, I was waiting to hear what the quite knowledgeable
and experienced experts had to say on this matter. I only
chose to post now because they seem shy at the moment.

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Featuring Gratuitous Alien Nudity