• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
boogyman19946

Manual Component Resizing

6 posts in this topic

In Java, does anyone know of some method by which I can let a layout manager resize components, but at the same time keep them in an aspect ratio? Currently the only way I found is to manually resize them, and I can't find a way to do this simply. My general way of constructing UIs is to set the properties of all the components before I add them to a container, and this gives me a lot of grief when it comes to resizing the components because I don't know how much space is available until I add the component to a container and the layout manager sizes it. I thought ComponentListeners would work, but I don't get a componentResized event unless I manually drag the border of the JFrame.

0

Share this post


Link to post
Share on other sites

I guess you could setPrefferedSize() then pack() every container so all sub components get the size you set with setPreferredSize() (maybe just packing the JFrame is enough).

 

That covers the default layout sizing (ie, when the components gets created and shown), after that you can handle manual resizing with the listener you already have.

0

Share this post


Link to post
Share on other sites

Wouldn't pack() resize my window though? In that case I don't want to pack the JFrame every time I switch between the menus just to resize the components inside it. 

I forgot to mention in my original post, and that's entirely my fault, that I still want the objects to scale with the window, but I want some of the components inside it to maintain a consistent width/height ratio. You see, I'm making a card game and I'm extending JButtons to represent the cards. If the button scales one dimension instead of both at once, then the cards end up stretched. What I generally do in this situation is probe the parent container to get the available space, and calculate the dimensions of the card to maximize the card's size while making sure it still looks like a card. I don't have a static value to pass to setPreferredSize because I generally calculate that based on the available space I have.

0

Share this post


Link to post
Share on other sites

Woot!

I don't know what it is about this forum, but many times when I posted the answer just sort of dawned on me shortly after.

 

I have managed to solve this ordeal by writing a custom layout manager that works like a FlowLayout, but, again, maintains a set aspect ratio. This provided me with a really nice solution and relieves me from having to include code for the layout where it shouldn't be. 

0

Share this post


Link to post
Share on other sites

It may not work for you this time, because of the learning curve, but I highly recommend MigLayout:

 

http://www.miglayout.com/

 

I know that you can layout out components and set the size to 40%, so it is always 40% of the current window size, and

you don't have to do anything.  While it can take a little while to figure out all the nuances, it is time well spent.

1

Share this post


Link to post
Share on other sites

Hey that looks like some good stuff! But you're right, it's a little complex to stick in my current project. I'll make sure to check it out for the next one though!

0

Share this post


Link to post
Share on other sites

On a side note, before Oracle bought Java, MigLayout was going to be included as a new LayoutManager in Java 7.0.  When Oracle took over it didn't happen, but Sun thought it was good enough to make the cut.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0