wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes JMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JMenu" Watch "JMenu" New topic
Author

JMenu

Jess Ishasder
Greenhorn

Joined: Feb 19, 2002
Posts: 21
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!
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMenu
 
Similar Threads
Implementing function in new dialog
one click and the whole ROW will be selected
Problem in ScrollPane's paint() method
JTABLE PROBLEM
Problem with String Tokenizer