This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Auto Resizing problem with JFrame  RSS feed

 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my small app, I have a JFrame that carries following components
1. A JTextPane carring a question
2. few JRadiobuttons
3. a Submit Button.

Now i exactly dont know what will be the length of the question or how many options will be there for each question. So i cant guess the size of the JFrame. What do i do to make the JFrame Auto resizable according to the Question length and number of options.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a frame going up/down in size would be a little strange.

how about working out the largest size possible then put your panel with components into a 'holding panel'

this holding panel will then take up all the unused space
 
Will Barbee
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a similar problem with a JFrame where I had a variable number of
lines to display in it, specifically a list of people attending a class. There might be 2, 6, 15, 4, etc.

So I set up a small loop to calculate the size of the JFrame to be used in a
JFrame.setSize() method.

The code looks like this:

The JScrollPane let me control the JPanel sizes. The center section was calculated also by the above.

As you see, I had a Header section of the frame with size 120. I had a Footer section set at 55.
The middle section of student names was calculated above as well.

So the JFrame and JPanel sizes were calculated based on the number of students and this caused
the JPanel and the JFrame to "auto-Size" based on some number of things. In your case, this would
be answers or options for your question displayed.
 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks i got your point that is a nice way but i need to test its performance in case teh data is large
 
Will Barbee
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shukla,
The center JPane is a JScrollPane which allows you to show only a part of the data and scroll to the rest.
As the programmer you can decide how large that section can be and thus how much data is scrolled.

Let me know how it turns out.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!