Swings Menu Bar
Hello,
I created a menu bar using Java Swings...
n New Record, Edit Record etc are the menu items.
Now, I want to display the appropriate fields according the menu Item selected..below it..
i.e.
If we selected New Record,
then Desired TextFields and new button should be displayed
and if we selected edit Record,
then the textfields related to editing and edit button should be displayed.
Everything should be displayed below the menu bar...
How to do this..??
or atleast what to use to get this..??
View Answers
March 15, 2010 at 11:28 AM
Hi Friend,
Try the following code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MenuData extends JFrame{
JTextField text1,text2,text3;
JLabel label1,label2,label3;
JPanel panel;
JButton button1,button2;
public MenuData(){
JMenuBar menuBar = new JMenuBar();
JMenu menu1 = new JMenu("Record");
JMenuItem item1 = new JMenuItem("Add Record");
JMenuItem item2 = new JMenuItem("Edit Record");
label1=new JLabel("ID:");
text1=new JTextField(20);
label2=new JLabel("Name:");
text2=new JTextField(20);
label3=new JLabel("Address:");
text3=new JTextField(20);
button1=new JButton("Add");
button2=new JButton("Edit");
panel=new JPanel(new GridLayout(4,2));
menuBar.add(menu1);
menu1.add(item1);
menu1.add(item2);
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(text3);
panel.add(button1);
panel.add(button2);
add(panel);
setJMenuBar(menuBar);
setVisible(true);
setSize(400,160);
label1.setVisible(false);
text1.setVisible(false);
label2.setVisible(false);
text2.setVisible(false);
label3.setVisible(false);
text3.setVisible(false);
button1.setVisible(false);
button2.setVisible(false);
item1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
label1.setVisible(true);
text1.setVisible(true);
label2.setVisible(true);
text2.setVisible(true);
label3.setVisible(true);
text3.setVisible(true);
button1.setVisible(true);
button2.setVisible(false);
}
});
item2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
label1.setVisible(true);
text1.setVisible(true);
label2.setVisible(true);
text2.setVisible(true);
label3.setVisible(true);
text3.setVisible(true);
button1.setVisible(false);
button2.setVisible(true);
}
});
}
public static void main(String args[]){
MenuData data=new MenuData();
}
}
Thanks
March 15, 2010 at 11:37 AM
The above answer is good...
But what i require is...
to delete a record i just need only one textfield to ask the user the id to delete the record
and to show a list there should be only one text area... to show the list of records..
Related Tutorials/Questions & Answers:
Swings Menu Bar - Java BeginnersSwings Menu Bar Hello,
I created a
menu bar using Java
Swings...
n New Record, Edit Record etc are the
menu items.
Now, I want to display the appropriate fields according the
menu Item selected..below it..
i.e.
If we
Menu Bar prob.Menu Bar prob. I want a
menu to be displayed in each page of my swing appl. how to go abt
Advertisements
menu bar in javascript - JSP-Servletmenu bar in javascript sir i need to display
menu bar with some background color.in each
menu,there are some values to display as menu.again if i select each value,again a sub
menu to display.plz send me some code.
menubar
Create Menu Bar in SWT
Create
Menu Bar in SWT
This section illustrates you how to create a
menu bar.
In SWT... to create a
menu bar. The method setMenu() sets the pull down
menu. The SWT.SEPERATOR
common Menu bar(toolBar) at the top of all viewcommon
Menu bar(toolBar) at the top of all view I creat on login page and after sign in I move to next page. Now I want to add
menu bar at the top of my all view. Any one have any idea abt how to do
Menu Bar in Java Menu Bar in Java
A
Menu Bar is a set of option that allow the user to choose from...; a user can
choose in a
menu bar. In this Tutorial we want to describe you how
Menu Bar in Java
Menu Bar in Java
A
Menu Bar is a set of option that allow the user to choose from any one...
choose in a
menu bar. In this Tutorial we want to describe you how to create a
Menu SWINGSSWINGS WHAT ARE THE DIFFERENCES BETWEEN AWT AND
SWINGS