• Post Reply Bookmark Topic Watch Topic
  • New Topic

window resizing  RSS feed

Greg Levine
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a GUI application using Java and Swing. The GUI portion of the application consists of two panels, one above the other. The frame is given a border layout so that the top panel can be placed in the NORTH section and the bottom panel can be placed in the WEST section. The top panel contains a text field and a button. The bottom panel contains a canvas for drawing shapes. This is where it starts to get tricky for me. The canvas must always be a perfect square. When the application loads, the top panel is filled and added to the frame. Then I have to figure out how much blank space is available for the bottom panel. The canvas must take up this blank space. But since it has to be a perfect square, the shorest side of the available space must be used as the value for the height and width of the canvas. I could pass all of this information along through the constructors of all of my components, but the reason I don't want to do this is because I also have to reconfigure the size of the canvas each time the window is resized. To me, it would make more sense to use a function in my class MyCanvas (which extends Canvas) to update the size of the canvas each time paint is called. I should also add that I am programmatically setting the size and location of the window based on the screen resolution when the application loads. Any ideas to help me solve this problem would be much appreciated.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!