Jump to content
  • Advertisement
Sign in to follow this  
Chryzmo

[java] Resizing JScrollPane

This topic is 4400 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I am writing a 2D map editor for my game. I am using Java Swing for the map editor, although the game itself will probably be written using C++ and SDL. I have a 2D array of MapTiles that contain the information of each tile in the map, if I start the program with a default of, say, 30x30 tiles, the JScrollPane has a scroll bar and it works correctly. If I click the new map button and resize the map to 5x5, thus not needing the scroll bars, they disappear and everything works properly. When I resize the map a larger size than the default starting size, the MapTile array is resized correctly, however the JScrollPane does not resize correctly. However, if I maximize, then restore the window, the JScrollPane will resize itself correctly. Is there someway I can do this automatically in the code when I want to resize the map? Thanks, Chris Moore

Share this post


Link to post
Share on other sites
Advertisement
http://java.sun.com/docs/books/tutorial/uiswing/TOC.html

Bookmark the above link.

I'm assuming you have an extended Jpanel in the Jscrollpane?

In which case you should do the following:

*Make sure the Jpanel implements scrollable
*When the Jpanels required size changes call setPrefferedSize on the Jpanel. getPrefferedViewportsize should probably just return getPrefferedSize (the same size you just set)
*To force JScrollBar to update when the above has occured call revalidate on the jpanel

I hope that helps...


[edit]
Before I forget, theres also a nice Java/Swing Opensource mapeditor here: http://mapeditor.org/

Share this post


Link to post
Share on other sites
Awesome! I had been trying to call revalidate on the JScrollPane, but calling it on the JPanel instead worked. Thanks a lot :-D

And I glanced at the map editor. I wanted to make this one, just to as a personal project, but I'll download the one you listed and check it out. Mine is very simple, so I would probably benefit more from a better made editor.

Thanks again,
Chris

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!