• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

JMenu

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a menu. Whenever a menu item is selected, the previous displayed components will be set invisible, and the new components will be set visible.
Suppose I have a menu button called, "Add". It has two menu items---"A Book" and "A CD".
First I selected "A Book", then selected "A CD". Those displays are good. However, when I selected "A Book" again, its components display is in a mess. Why?
The following is part of my code:
=================================
.......
addBook.addActionListener(new AddBookListener(this, c));
addCD.addActionListener(new AddCDListener(this, c));
.......
class AddBookListener implements ActionListener
{
private Exer3 myApplet=null;
private Container myContainer = null;
//Constructor
public AddBookListener(Exer3 app, Container c){
myApplet = app;
myContainer = c;
}
//Define actionPerformed()
public void actionPerformed(ActionEvent e){
//Clear the pane by calling a helper method--invisibleAll()
helperClass help= new helperClass(myApplet);
/*=====Set Invisible======*/
help.setInvisibleForAddCD();
/*=====Set visible========*/
help.setVisibleForAddBook();
//Design the layout of the pane
designLayout();
//Ensures that the Container has a valid layout
myApplet.validate();
....
....
(AddCDListener did the same thing)
}//End of actionPerformed()
.....
.....
class helperClass{
Exer3 myApplet= null;
public helperClass(Exer3 app)
{
myApplet = app;
}
/*===========Set Visible====================*/
public void setVisibleForAddBook()
{
myApplet.lblHead1.setVisible(true);
myApplet.lblCata1.setVisible(true);
......
......
public void setVisibleForAddCD()
{
myApplet.lblHead2.setVisible(true);
myApplet.lblCata2.setVisible(true);
......
......
public void setInvisibleForAddBook()
{
myApplet.lblHead1.setVisible(false);
myApplet.lblCata1.setVisible(false);
......
......
public void setInvisibleForAddCD()
{
myApplet.lblHead2.setVisible(false);
myApplet.lblCata2.setVisible(false);
.....
......
Please help me to solve the problem.
Thank you for your help!
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jess,
If the same components are getting set visible/invisible over and over again you really should be using a CardLayout with the components required for one menu item on one panel and the others on another panel. Then you only need to set the front card and it won't matter how many components are on each card, etc.
Regards,
Manfred.
 
reply
    Bookmark Topic Watch Topic
  • New Topic