0

menu screen

This is my menu screen. It is a JTabbedPane that when the user clicks on any of the tabs I set the menu's visibility to false and set visibility of another tabbed pane to true. Say the user clicked on stock, then the window will look something like this:

Stock Screen

When the user clicks on the "<<" tab it will set stock's visibility to false and menu's visibility to true.

Is it better to just create multiple JFrame files and do the same instead of adding multiple TabbedPanes inside a single frame? It's getting kind of hard to maintain the single .java file for the entire JFrame.

Community
  • 1
  • 1
Rahul D'Mello
  • 90
  • 1
  • 10
  • 1
    If you have a single file, then you're not applying the MVC and OOP concepts right.... And see [The use of multiple JFrames, Good / Bad Practice?](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-or-bad-practice) (BAD) also take a look at the [Card Layout](https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html) to change between views instead of changing visibilities – Frakcool Sep 26 '16 at 20:03
  • thank you for the tips i will take a look at card layout right away :D i do have multiple java files each dealing with different functionalities but only 1 file with all the gui and events and it was getting hard to maintain all the event code and adding components and everything in one single java file so i asked if i should rather make multiple jframes the other files only deal with insert and other such operations but there objects were created in that jframe file itself – Rahul D'Mello Sep 26 '16 at 20:21
  • Not sure I full understand the hierarchy here, but it seems like each item of the main menu may have multiple child items? Do those in turn have children? Perhaps a JTree - which will allow for visibility of both the parent and child actions at the same time - then use a `CardLayout` to switch between views based upon clicks on the tree nodes. – copeg Sep 26 '16 at 22:23
  • each item in main menu have multiple child items they dont have any children. so far after reading all these replies i have decided to create multiple jpanel forms and adding them to a panel in a jframe and used cardlayout to switch between them on the basis of which tab the user selects in the main menu – Rahul D'Mello Sep 27 '16 at 12:51

2 Answers2

3

Yes you can also do this,in this way:

JTabbedPane preupdatetab = new JTabbedPane();
preupdatetab.setForeground(new Color(255,0,0).darker());
preupdatetab.setBounds(30,15,930,300);
preupdate.add(preupdatetab);
precomplete.setLayout(null);
preupdatetab.add(precomplete,"Complete Change");
preonce.setLayout(null);
preupdatetab.add(preonce,"Qty Change");
changelocationpanel = new JPanel();
changelocationpanel.setLayout(null);
preupdatetab.add(changelocationpanel,"Change Location");
changesaleprice = new JPanel();
changesaleprice.setLayout(null);
preupdatetab.add(changesaleprice,"Change Sale Price");
changebookprice = new JPanel();
changebookprice.setLayout(null);
preupdatetab.add(changebookprice,"Change Book Price");
changevendor = new JPanel();
changevendor.setLayout(null);
preupdatetab.add(changevendor,"Change Vendor");
changeitemname = new JPanel();
changeitemname.setLayout(null);
preupdatetab.add(changeitemname,"Change Item Name");

The other variables are globally declared JLabel so don't be confused and the following picture will clear you more about this. enter image description here

Shahab Khan
  • 542
  • 2
  • 10
  • so in your examples theres only 1 .java file for a jframe that has a jtabbedpane and the jtabbedpane has mutiple jtabbedpanes added in it ? – Rahul D'Mello Sep 26 '16 at 20:05
  • `changeitemname.setLayout(null);` Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Sep 27 '16 at 01:23
  • I am not understanding what you are saying about what now should i do after putting setlayout(null) – Abdullah Nasir Sep 27 '16 at 05:40
2

I have a similar menu style in one of my applications. I would do one of the following:

  1. For better organization I would move your second JTabbedPane to another JFrame and swap the code out. This would be quick, give you no new functionality, but would make your code easier to keep track of.
  2. As the other poster showed you can do both tabs above. This would separate the code and give the user the functionality of going "Up a level" without having to go "back".
  3. What I like to do is a combination of the two. For the main menu, keep your tab on the left but for the sub menus have a separate JTabbedPane above that loads into the frame when the first menu is accessed. It gives your windows a clean look, a way to easily navigate everything, and it will train the users to look left for big changes and up for smaller ones. That way, once your users are comfortable with that you can make more menus act that way and it becomes more intuitive the more they use it.
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
CallSign-Filter
  • 1,283
  • 1
  • 9
  • 12