0

What I am looking for is a way to navigate through different JPanels in just one JFrame. To navigate the user should use buttons located inside these panels.

I am no using any layouts. I want all my jpanels in the same position.when we submitting the corresponding button

I hope you guy's can help me out, i Have a menubar in my jframe and for each item different panels.

Lijo
  • 6,498
  • 5
  • 49
  • 60
  • 1
    *"I am no using any layouts."* Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). Further, I cannot see this question as being solved when using `null` layouts, so save yourself some time and learn how to use them now. – Andrew Thompson Dec 10 '13 at 06:18
  • thank you for your advice i will definitely try it – Lijo Dec 10 '13 at 06:59

1 Answers1

5

You will want to use a CardLayout, it was designed to allow you to switch the active panel from one panel to another.

Unless you intend never to run you program on any other PC other then the one it was created (and never update the OS or hardware), you will want to learn to make use of layout managers.

PC's come in all shapes and sizes, with differences between OS's (and versions of OS's), display drivers and screens which will all make your program look different on each system it is run on. Layout managers take out the guess work involved in trying to deal with these situations.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • but i am not using carlayout i have already write the whole programme using setbounds. – Lijo Dec 10 '13 at 05:18
  • @404 If you want away to switch between views, there it is. If you want to re-invent the wheel, then you are free to do that as well. – MadProgrammer Dec 10 '13 at 05:21
  • but i cant use carlayout. – Lijo Dec 10 '13 at 05:21
  • but i have menubar in the jframe and for each menu items i have different panels.so how can i use tabbedpane – Lijo Dec 10 '13 at 05:23
  • @404 If you really want to. Insert a `JPanel` between your current UI and the frame that has a `CardLayout` assigned to it. Then add your current UI to this panel. Use the `CardLayout` to manage the current active view... – MadProgrammer Dec 10 '13 at 05:23
  • +1, `but i cant use cardlayout.` - sure you can. `for each menu items i have different panels` - this is a perfect use for a CardLayout. `i have already write the whole programme using setbounds` well you should be using layout manager, but even if you don't listen to our advice, this will not prevent you from using a CardLayout to contain the panels you want to swap. – camickr Dec 10 '13 at 05:38