Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

scrollPane not quite working as expected

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Scotty Steven

I could kiss you! Once I realized that 500x500 was too small to trigger anything and changed it to read the actual over-sized drawing, things started working as they should. Thank you for providing me the steps that I needed to take, which I guess is what @Rob Camick was cryptically also trying to tell me.
 
Rancher
Posts: 3205
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Would it really hurt you after a week to maybe put out a little extra effort and give her the answer



@scotty, Yes, it would hurt. I don't believe in spoon feeding the answer when people asking are not willing to make an effort. 4 times I had to ask for a SSCCE before one was created. 4 times I mentioned the getPreferredSize() method need to be implemented. Yet this was still NOT done when the SSCCE was posted and there was no evidence that she even attempted to implement the method. If you don't know how to implement the method you can always search the forum/web for that method name and find plenty of examples to give you ideas on how you might implement the method. You get what you give.

but the component console size printout is still showing 0x0



All components are created with a 0 size and location. The size and location is determined by the layout manager. The layout manager is not invoked until you pack() the frame or make the frame visible.

the jScrollPane is still not there.



That is because you used the pack() method so all components are displayed at their preferred size so there is no reason for the scrollbars to appear. Use your mouse to resize the frame smaller and the scrollbars will appear. This is why it is important to have a proper implementation of the getPreferredSize() method, so the scrollbars will appear as needed.

A better implementation of the getPreferredSize() method should take advantage of your knowledge of your class. In your case all you painting is done based on the values of hard coded variables you can just use a mathematical formula:



In this case a dimension of (2440, 1240) is returned. This is too large to display on a monitor so you should not use the pack() method on your frame. Instead use something like setSize(800, 600) to make the frame size more reasonable and you will see the scrollbars automatically.

Other comments:

1. Don't call you class Rectangle. There is already a Rectangle class in the JDK by that name so it get confusing
2. Follow standard Java naming conventions. Class names should not have an "_" in the name. There are no classes like this in the JDK or any text book or tutorial that I have ever seen, so don't make up your own conventions.
 
Jenn Terry
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

4 times I mentioned the getPreferredSize() method need to be implemented. Yet this was still NOT done when the SSCCE was posted and there was no evidence that she even attempted to implement the method. If you don't know how to implement the method you can always search the forum/web for that method name and find plenty of examples to give you ideas on how you might implement the method. You get what you give.



It's not that I didn't try to use it. It was that I didn't try to use it correctly and didn't understand what you were asking me to do. I did not include it in the SSCCE as I did not realize that not posting something that didn't work for me would offend you so bad.

That is because you used the pack() method



I did this as one of the experiments and already removed it and placed back the code

1. Don't call you class Rectangle. There is already a Rectangle class in the JDK by that name so it get confusing



I was not aware of that, but I also was not the one who created the Class. I will refactor.

2. Follow standard Java naming conventions. Class names should not have an "_" in the name. There are no classes like this in the JDK or any text book or tutorial that I have ever seen, so don't make up your own conventions.



In normal code, I do not do this. I was just doing this so that I had some sort of reference back to which class it actually belonged to in the actual program.

 
Ranch Hand
Posts: 80
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am so glad I could help. Sometimes, when a person is too close to a project, they can't see the answer that is right in front of them clearly. Sometimes, more can be learned by a bit of spoon feeding then by causing them frustration. I'm pretty new and know what it is like to be sitting there with a problem and a teacher who knows the solution chooses to make you feel like a dummy. I guess that's how they get to feel superior.
    Bookmark Topic Watch Topic
  • New Topic