Unable to expand window

Reply

Join Date: Sep 2009
Posts: 28
Reputation: bruceaj is an unknown quantity at this point 
Solved Threads: 0
bruceaj bruceaj is offline Offline
Light Poster

Unable to expand window

 
0
  #1
17 Days Ago
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..

  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);
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 18
Reputation: AndreiDMS is an unknown quantity at this point 
Solved Threads: 0
AndreiDMS AndreiDMS is offline Offline
Newbie Poster
 
1
  #2
16 Days Ago
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)
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 28
Reputation: bruceaj is an unknown quantity at this point 
Solved Threads: 0
bruceaj bruceaj is offline Offline
Light Poster
 
0
  #3
16 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 18
Reputation: AndreiDMS is an unknown quantity at this point 
Solved Threads: 0
AndreiDMS AndreiDMS is offline Offline
Newbie Poster
 
0
  #4
15 Days Ago
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:

  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; 15 Days Ago at 7:51 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 28
Reputation: bruceaj is an unknown quantity at this point 
Solved Threads: 0
bruceaj bruceaj is offline Offline
Light Poster
 
0
  #5
15 Days Ago
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....
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 18
Reputation: AndreiDMS is an unknown quantity at this point 
Solved Threads: 0
AndreiDMS AndreiDMS is offline Offline
Newbie Poster
 
0
  #6
14 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 28
Reputation: bruceaj is an unknown quantity at this point 
Solved Threads: 0
bruceaj bruceaj is offline Offline
Light Poster
 
0
  #7
13 Days Ago
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; 13 Days Ago at 5:11 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 18
Reputation: AndreiDMS is an unknown quantity at this point 
Solved Threads: 0
AndreiDMS AndreiDMS is offline Offline
Newbie Poster
 
0
  #8
13 Days Ago
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
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC