This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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.
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).
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)