• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding Panels in Frame or in a Panel

 
Tahir Abbas
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to everyone,

I checked some examples of gui programs that extends JFrame, have multiple panels then these panels are added in Frame(Container c = getContentPane() then c.add(panelName),...). But my approach is little bit different.

I wrote gui files with extends JFrame approach. The files have multiple panels and these panels are finally added in another main panel then I get display that main panel (setContentPane(mainPanel)) so instead of putting panels in JFrame I am putting panels in another panel.

I am not sure which approach is better. I would like to know your opinion.

Thanks in advance
Best Regards!
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there, are you using layout managers? Ideally, it all depends on how you want the GUI to look. Using a BorderLayout (JFrame default) as an example, you can have up to 5 panels (top, left, botton, right, center). Each panel again depend on what you want on it can have its own layout manager and panels. Therefore, it's really up to your imagination.

As for SCJD is concern, keep it simple. Use basic layout managers. If you are not good with GrigBagLayout, don't use it. Don't try to be too fancy. As for your case, you may want to reuse panel variables. Ultimately, it is the events from text fields, drop down menus, buttons that you need to worry about.
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tahir,

My MainWindow is also extending JFrame and I followed the same approach as you: panels adding to another panel and then calling setContentPane


Kind regards,
Roel
 
Tahir Abbas
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! K. Tsang and Roel De Nijs

My program's first window shows components to open application in required mode (Server/Client/SAlone). The main panel has Grid layout. (mainPanel.setLayout(new GridLayout(9,0))) other child panels has Flowlayout. Then I put all these panels in mainPanel.

This window will disappear after the selection of mode. Then a window with menu will appear that will have menu options. I'll try to get all processing in the same window(frame). Different panels according to required command will apear/disappear in the same frame. This time I dont know how to keep the vertical size of top most panel(that has menu) very thin. But I'd like to do this without the GridBagLayout.

I know many things I'm discussing here are of basic level but infact I'm building almost all gui once again just because of using setlayout(null) in first developed client side interface, so now dont want to repeat such a mistake.

Roel I felt confidence to know that you also used the same approach(Panels inside panel).

Best Regards!
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tahir,

In my opinion you can't create a good MainWindow (with search criteria, jtable and some buttons) without using a GridBagLayout. But that's my opinion and of course GridBagLayout is not the most easy to use layout available in Java. But layouting and creating GUIs is simply one of the hardest things to do in Java (certainly compared with vb or vb.net)

I just used the following 3 layouts:
  • BorderLayout
  • FlowLayout
  • GridBagLayout


  • Kind regards,
    Roel
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic