Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Swing / JScrollPane / setPrefferedSize question...  (Read 988 times)
0 Members and 2 Guests are viewing this topic.
Offline Eli Delventhal
« League of Dukes »

JGO Kernel
*****

Posts: 3575
Medals: 44


Game Engineer


« on: 2009-04-22 19:44:19 »

Hey all.

I've basically got code like this:

JFrame has a JScrollPane in it which contains a JPanel. All this is created, the JFrame is shown, user can do whatever they want. User chooses a menu item that loads in a background image to the JPanel. The JPanel does the code to load in the image, then it says setPreferredSize(image.width, image.height). Unfortunately, the JScrollBar refuses to recognize the difference change until I resize the window. Then once the window is resized, scroll bars appear within the JScrollPane.

Does anyone know of some sort of update method I can call on the JScrollBar or the JPanel (or anything, really) that will cause the JScrollBar to recognize that the preferred size of the JPanel changed?

Thanks.

See my work:
OTC Software
<br />
Currently Working On:
Secret project...
Quote from: _Riven
I edit JGO in production, because I simply don't waste time writing bugs
Offline CommanderKeith

JGO Wizard
****

Posts: 1455
Medals: 9



« Reply #1 on: 2009-04-22 22:21:01 »

Try calling revalidate() on the JScrollPane.

All JComponents have that method (from memory...)

Offline JonathanC

Jr. Member
**

Posts: 53



« Reply #2 on: 2009-04-23 00:31:23 »

It might help you to see it in a larger context. This classic example helps:

How to Use Scroll Panes
Games published by our own members! Go get 'em!
Offline Eli Delventhal
« League of Dukes »

JGO Kernel
*****

Posts: 3575
Medals: 44


Game Engineer


« Reply #3 on: 2009-04-27 13:42:32 »

Revalidate did the job. Weird, because I thought I had tried that before. Thanks guys.

See my work:
OTC Software
<br />
Currently Working On:
Secret project...
Quote from: _Riven
I edit JGO in production, because I simply don't waste time writing bugs
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.054 seconds with 19 queries.