-1

Can anyone give me an example of how to put a panel of a determined size over another panel of determined size inside a JFrame?

i mean something like this

-------------------
|                 |
|       Panel 1   |      
|                 | 
|                 |
-------------------
|                 |
|      Panel 2    |                                         
-------------------
user2488345
  • 63
  • 1
  • 1
  • 8
  • @GilbertLeBlanc he is (presumably) adding a panel to a panel. –  Jun 21 '13 at 18:31
  • 1
    @DaftPunk, that is for the OP to express clearly. He could be trying to use a CardLayout type situation where two panels occupy the same space but only one is visible at a time), or maybe he is trying to paint a semi-transparent panel on top of another panel, or maybe just add a child panel to a parent panel. As I stated earlier it is up to the OP to post a clear question so we don't spend time guessing. – camickr Jun 21 '13 at 18:33
  • sorry i explaned my self in the wrong way ill edit – user2488345 Jun 21 '13 at 18:44
  • [GridBagLayout](http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html) is your friend in this case, some related examples can be found [here](http://stackoverflow.com/a/10979659/1057230), [here](http://stackoverflow.com/a/11166903/1057230) and [here](http://stackoverflow.com/a/14757600/1057230). As requested special link to how [**accepting an answer**](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) works :-) – nIcE cOw Jun 22 '13 at 01:21

2 Answers2

1

Read the section from the Swing tutorial on Layout Managers. There are several you can choose from. BorderLayout may be the easiest as it does automatic resizing of the width.

Note that you should not be hardcoding sizes. Let the layout manager determine the size.

camickr
  • 321,443
  • 19
  • 166
  • 288
1

Have a look at the JSplitPane Swing Component.

I would suggest for you to read How to use Split Panes, and the layout manager links from camickr's answer

John McDonnell
  • 753
  • 1
  • 8
  • 24