944,132 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 857
  • Java RSS
Nov 6th, 2009
0

Unable to expand window

Expand Post »
I have a GUI window with a JFrame. On this JFrame, I have a JPanel that completely covers the JFrame. I then have another JPanel within this first JPanel that contains a text box and 3 buttons. Within an event handler, I want to expand the JFrame and 2 JPanels by a height of 20 px. I then want to move down the text box and 3 buttons, 20 px.

I can expand the JFrame and the first JPanel with the following code snip. But, it doesn't work on the second panel nor does it work to move the button down.

Appreciate your help. Thanks..

Java Syntax (Toggle Plain Text)
  1. // Make room for an additional text box
  2. int heightInc = 20;
  3.  
  4. Dimension frameSize = new Dimension();
  5. Rectangle rectangle = new Rectangle();
  6.  
  7. // Adjust JFrame size (This Works)
  8. frameSize = this.getSize();
  9. frameSize.height += heightInc;
  10. this.setSize(frameSize);
  11.  
  12. // Adjust the bounding JPanel size (This Works)
  13. frameSize = jplFrame.getSize();
  14. frameSize.height += heightInc;
  15. jplFrame.setPreferredSize(frameSize);
  16.  
  17. // Adjust the AddSubtitle JPanel size (This doesn't work)
  18. frameSize = jplAddSubtitle.getSize();
  19. frameSize.height += heightInc;
  20. jplAddSubtitle.setPreferredSize(frameSize);
  21.  
  22. // Move the "Add Another" button down (This doesn't work)
  23. rectangle = btnAddAnother.getBounds();
  24. rectangle.y += heightInc;
  25. btnAddAnother.setBounds(rectangle);
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
bruceaj is offline Offline
28 posts
since Sep 2009
Nov 7th, 2009
1
Re: Unable to expand window
What layout manager are you using?

The default layout for JPanel is FlowLayout witch puts components in a row, If you like to set the element position and size you should use another layout like null (for absolute positioning)
Reputation Points: 10
Solved Threads: 9
Junior Poster in Training
AndreiDMS is offline Offline
68 posts
since Oct 2009
Nov 7th, 2009
0
Re: Unable to expand window
I am not using any explict layout manager. I'm using the "free flow" or whatever netbeans call it when you simply move components onto the panel.

Does this help you on giving me some help?

Thanks for the response.
Reputation Points: 10
Solved Threads: 0
Light Poster
bruceaj is offline Offline
28 posts
since Sep 2009
Nov 8th, 2009
0
Re: Unable to expand window
Ok then, netbeans uses free design witch actually is GroupLayout if you take a look in the generated code for components initialization.
You could change the layout to Absolute for the both Panels and then use:

Java Syntax (Toggle Plain Text)
  1. // Adjust the AddSubtitle JPanel size
  2. rectangle = jplAddSubtitle.getBounds();
  3. rectangle.height += heightInc;
  4. jplAddSubtitle.setBounds(rectangle);
  5. // Move the "Add Another" button down
  6. rectangle = btnAddAnother.getBounds();
  7. rectangle.y += heightInc;
  8. btnAddAnother.setBounds(rectangle);
Last edited by AndreiDMS; Nov 8th, 2009 at 7:51 am.
Reputation Points: 10
Solved Threads: 9
Junior Poster in Training
AndreiDMS is offline Offline
68 posts
since Oct 2009
Nov 8th, 2009
0
Re: Unable to expand window
Thank you for your response. I guess I'm too much of newbie and novice to change the layout to Absolute. I have "struggled" for couple of hours trying to get something to work. No success.

So, if you would, I'd greatly appreciate a little detail on how I can do as you suggests. Thank you....
Reputation Points: 10
Solved Threads: 0
Light Poster
bruceaj is offline Offline
28 posts
since Sep 2009
Nov 9th, 2009
0
Re: Unable to expand window
Did you managed to set the layout to absolute for the panels?

What exactly it's not working?

After setting the layout(you might need to resize and reposition the components after that) you just have to replace your code that doesn't work with the one I've posted.
Reputation Points: 10
Solved Threads: 9
Junior Poster in Training
AndreiDMS is offline Offline
68 posts
since Oct 2009
Nov 10th, 2009
0
Re: Unable to expand window
I was unable to set the layout to Absolute. I just don't know how to do it. I'm too new at the Java stuff. I ended up realizing I had no idea how to proceed. Do I delete everything I have layout with NetBeans "Free Design" and start over specifying Absolute layout? Or, can I insert some code that will over ride the GrouplLayout with the Absolute Layout. You can see, I really don't understand the mechanism of using any of the layout managers other then the "Free Design.: Maybe in a couple of months, I be "smarter."

So, I took the lazy way out and changed my design so I don't need to expand the dialog.
Last edited by bruceaj; Nov 10th, 2009 at 5:11 pm.
Reputation Points: 10
Solved Threads: 0
Light Poster
bruceaj is offline Offline
28 posts
since Sep 2009
Nov 10th, 2009
0
Re: Unable to expand window
In your Design view, just select the Panel you want to set the layout for then right-click on it -> select Set Layout -> Absolute Layout (or any other layout you want to use).

Read this A Visual Guide to Layout Managers, I'm sure It will help you to get started

GL with your programming
Reputation Points: 10
Solved Threads: 9
Junior Poster in Training
AndreiDMS is offline Offline
68 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Error Message
Next Thread in Java Forum Timeline: public void close () VS. private void close ()





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC