Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can scrollPane be resized automatically?  RSS feed

 
Sandeep Mukherji
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when we resize a JFrame, is it possible to resize the containing scroll pane with the frame automatically? is there any function?
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it? I would have thought most of the layout managers would automatically resize all Components. So don't use null layout.

Please tell us what happens when you try.
 
Sandeep Mukherji
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
This is the following snap of code that I have tried. But can not resize scroll pane with the frame.


It's not working...
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using setBounds for anything other then a top-level container? If you set the size of the panel you are adding the scroll pane to, there cannot be any change of size. That might be your problem.
 
Sandeep Mukherji
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Part1 of my application.

Part2 of my application.

To set the components at the right places I have to use the setBounds. I am using setBounds to fix the labels, textboxes and the buttons on the toplabel container. then the top conatiner is being fixed on the base container as:

and then the basePanel is added on the main Frame as:

here frameSizeX and frameSizeY are int type and I set the size of the frame using these. If I do not use line 1 or line 2 then the frame will not show anything.
 
Sandeep Mukherji
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A little change on the above post instead of
*the basePanel is added on the main Frame as
the basePanel is added on the ScrollPanel and scrollPane is added on the main frame in turn.
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what sort of LayoutManager are you using on the Frame? You may find there is no change of size if you use null layout, whereas you will get change of size with Grid or GridBag. I think you get a change of size with Border, too.
 
Sandeep Mukherji
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On frame i am using the BorderLayout, and fixed the scrollpane on it using add(scrollPane, BorderLayout.CENTER);
 
Sandeep Mukherji
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Mr. Ritchie,

You were right. I was using null layout for the frame layout. Now I have turned it to BorderLayout and its workibg perfect.

Thanks a lot.
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sandeep Mukherji:
hello Mr. Ritchie, I was using null layout for the frame layout. Now . . . its workibg perfect.

Thanks a lot.
You're welcome
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!