Swings Menu Bar

Ads

 
 

Share on Google+Share on Google+

Valli
Swings Menu Bar
2 Answer(s)      7 years ago
Posted in : Java Beginners
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..??
Ads
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..

Ads









Related Tutorials/Questions & Answers:
Swings Menu Bar - Java Beginners
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
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-Servlet
menu 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 view
common 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
How to remove the background color of bootstrap menu bar?
How to remove the background color of bootstrap menu bar?  Hi, What css can be used to remove the color of bootstrap menu bar? thanks   ... the background image for the nabvar in a bootstrap based menu. Thanks
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
SWINGS
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
menu
menu  Hi,i want write the menu that repeat several time
menu
menu  fibonaci & prime no. display in menu driven in java programme
Menu
Menu  Pl make a program which generates the following output. "Select from this menu" 1. Array 2. Stack 3. Queue. 4. Exit. If users press 1, then it will go in 1. Array. Welcome in Array. press 1. for Insertion press 2
Swings/awt - Swing AWT
Swings/awt  Hi, how to write action listeners to the Buttons in RichTextEditor tool bar.. thanks in advance...it's Urgent... i am very much new to Swings
Bar graph
Bar graph  How to include a bar chart in iPhone sdk
menu with scrollbar
and every component should inside the panel. I tried it but menu bar... java.awt.*; public class menu extends JFrame { MenuBar bar; Menu file,setting,rate,help,crate,prate; public menu() { JFrame frame =new JFrame("Stock Analysis"); bar
bar chart
bar chart  how to create a bar chart from values of the database and the string value should be the entities of the database??plzz help..needed badly
Create Bar graph
Create Bar graph  hi............. In my project i want to create a BAR GRAPH to display the result. I HAVE certain values that want to show in graph form. Can u help me plzzzzzzz i require a very simple code in java swings were
Bar Chart
Bar Chart  hi...... Thanks 4 ur help for the bar graph creation i have got what i wanted. But now want to ask that in that bar graph i want multiple bar on one value means I want to create a graph where on my x-axis i have
JSP & Swings
JSP & Swings  How to integrate jsp and swings
Progress Bar
Progress Bar  Hi friend, I'm interested in knowing how to progress bar in oracle forms 9i for the trigger when-button-pressed.Thankyou. Thanks and Regards, M.SHANKAR
progress bar
progress bar  Hi guys, I'm doing a file upload in spring MVC technology. For file upload i did validation in client side.While uploading how to use an ajax function to show the progress bar
swings question
swings question  how to change the background color with the help of color values by using swings
java swings - Swing AWT
the performance of the employees by using bar bharts. Please give me how can we write the code for bar charts using java swings.  Hi friend, I am.... http://www.roseindia.net/java/example/java/swing/draw-simple-bar
swings for webnms
swings for webnms  if i am expanding node of jtree then i want to collapse previous expanding node of jtree in swings how is it possible
How to design a bar code, design a bar code, bar code
How to design a bar code       This tutorial will teach you to design a bar code, the bar code... to Filter Menu > Noise > Add Noise and use these settings. Motion Blur
Jquery Slide-up Menu
Jquery Slide-up Menu  Hello, Excellent site. I am learning Jquery and I can produce a slide-down menu but don't know how to make a slide-up menu/nav bar to go at the bottom of the web page. Can you show a way how this can
Java Swings-awt - Swing AWT
Java Swings-awt  Hi, Thanks for posting the Answer... I need to design a tool Bar which looks like a Formating toolbar in MS-Office Winword(Standard & Formating) tool Bar. Please help me... Thanks in Advance
menu driven
menu driven   menu driven programm in decimal to binary binary to decimal
menu driven
menu driven  display the 1-30 prime no. and fibonacie series in menu driven programme
swings - Java Beginners
. In that application i created a menu bar,it contains menu items like file,Edit, view, map,analysis etc. In this i only developed the code for file, edit,viem menu items.Only... to disable these items in the application, means these items r appear in the menu
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes