How to open textfields in the the same panel of the jframe by selcting from dropdown menu option ...

How to open textfields in the the same panel of the jframe by selcting from dropdown menu option ...

Hello Sir, I have a dropdown menu and i have to show textfields and submit button on the basis of the selection of option from the dropdown menu .acc. to my requirement i have to show the textfields and submit button in the same panel of the jframe window .

Below is my code which is displaying textfields in the other jframe. KIndly help me sir

Plz sir have a look of my code to sort out problem.

will always be gratefull.Thank you Sir.

  
  import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import javax.xml.soap.Detail;

public class ComboBox{
public static void main(String[] args) {
 ComboBox b=new ComboBox();
  }
  public ComboBox(){
  final JComboBox combo;
  JTextField txt;
  JButton b=new JButton("GO");
  String course[] = {"Detail Report","Summary Report"};
  final JFrame frame = new JFrame("Creating a JComboBox Component");
  final JPanel panel = new JPanel();
  combo = new JComboBox(course);
  combo.setBackground(Color.white);
  combo.setForeground(Color.red);

  panel.add(combo);
  panel.add(b);
  frame.add(panel);

  combo.addItemListener(new ItemListener(){
    public void itemStateChanged(ItemEvent ie){
    String str = (String)combo.getSelectedItem();
    }
  });
   combo.setBounds(10,10,100,20);
   b.setBounds(120,40,80,20);
   panel.setBounds(10,70,480,170);
   b.addActionListener(new ActionListener() {

   public void actionPerformed(ActionEvent e) {
            JPanel p=new JPanel();
               JFrame f=new JFrame();
  f.setDefaultCloseOperation(JFrame.EXITONCLOSE);
  f.setSize(450,400);
  f.setLocationRelativeTo(null);
  f.setVisible(true); 
            String str3 = (String)combo.getSelectedItem();
                 String str2="Detail Report";
                 System.out.println(str3);
                 if(str3.equals(str2)){
                 JLabel l1=new JLabel("Date1:");
                 JTextField txt1=new JTextField(12);

           p.add(l1);
             p.add(txt1);  
             f.add(p);
            f.setVisible(true);
            }


            else{
               JLabel l2=new JLabel("Date2:");
             JTextField txt2=new JTextField(12);
                 p.add(l2);
             p.add(txt2);  
             f.add(p);
                f.setVisible(true);

            }  


        }
});
  frame.setDefaultCloseOperation(JFrame.EXITONCLOSE);
  frame.setSize(450,400);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
  }
}
View Answers

July 13, 2012 at 5:26 PM

Here is a code that open textfields in the same jframe by selcting from dropdown menu option.

import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import javax.xml.soap.Detail;

public class GenerateReport{
public static void main(String[] args) {
 GenerateReport b=new GenerateReport();
  }
  public GenerateReport(){
  final JComboBox combo;
  JTextField txt;
  JButton b=new JButton("GO");
  String course[] = {"Detail Report","Summary Report"};
  JFrame frame = new JFrame("Creating a JComboBox Component");
  frame.setLayout(null);

  combo = new JComboBox(course);
  combo.setBackground(Color.white);
  combo.setForeground(Color.red);
   final JLabel l1=new JLabel("Date1:");
   final JTextField txt1=new JTextField(12);
   final JLabel l2=new JLabel("Date2:");
   final JTextField txt2=new JTextField(12);

    combo.addItemListener(new ItemListener(){
    public void itemStateChanged(ItemEvent ie){
    String str = (String)combo.getSelectedItem();
    }
  });
   combo.setBounds(10,10,100,20);
   b.setBounds(10,40,80,20);
   l1.setBounds(10,70,100,20);
   txt1.setBounds(120,70,100,20);
   l2.setBounds(10,110,100,20);
   txt2.setBounds(120,110,100,20);

  frame.add(combo);
  frame.add(b);
  frame.add(l1);
  frame.add(txt1);
  frame.add(l2);
  frame.add(txt2);
  l1.setVisible(false);
  txt1.setVisible(false);
  l2.setVisible(false);
  txt2.setVisible(false);

   b.addActionListener(new ActionListener() {

   public void actionPerformed(ActionEvent e) {

            String str3 = (String)combo.getSelectedItem();
                 String str2="Detail Report";
                 System.out.println(str3);
                 if(str3.equals(str2)){
                     l1.setVisible(true);
                     txt1.setVisible(true);
                     l2.setVisible(false);
                     txt2.setVisible(false);

                 } 
                 else{
                     l1.setVisible(false);
                     txt1.setVisible(false);
                     l2.setVisible(true);
                     txt2.setVisible(true);              

                 }  
        }
});
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(450,400);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
  }
}

July 13, 2012 at 5:51 PM

Thank you deepak .Thank you very much......









Related Tutorials/Questions & Answers:
How to open textfields in the the same panel of the jframe by selcting from dropdown menu option ...
How to open textfields in the the same panel of the jframe by selcting from... of option from the dropdown menu .acc. to my requirement i have to show the textfields and submit button in the same panel of the jframe window . Below is my
how to show search results in the same panel of jframe to where search field and button is present..
how to show search results in the same panel of jframe to where search field... ,In the given code search results is being displayed in the other jframe. But in my application i need to show search results in the same panel of jframe to where
Advertisements
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
How to invoke other java class by selecting from dropdown menu... a dropdown menu to choose type of report and then click on submit button.On clicking submit button should show the user various textfields on the same panel from
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
How to invoke other java class by selecting from dropdown menu... a dropdown menu to choose type of report and then click on submit button.On clicking submit button should show the user various textfields on the same panel from
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
How to invoke other java class by selecting from dropdown menu... a dropdown menu to choose type of report and then click on submit button.On clicking submit button should show the user various textfields on the same panel from
how to show search results in the same panel of jframe to where search field and button is present..
how to show search results in the same panel of jframe to where search field... where i have to show the search result in the same panel of where search field and Button is present .I have code which is doing the same work but when i enter
Displaying search results in same panel of gridview in same jframe window.
Displaying search results in same panel of gridview in same jframe window.  Hello Sir, I have a search frame window from which we can search and see the results in the same panel of the Jframe in Gridview Jtable
Displaying search results in same panel of gridview in same jframe window.
Displaying search results in same panel of gridview in same jframe window.  Hello Sir, I have a search frame window from which we can search and see the results in the same panel of the Jframe in Gridview Jtable
How to backup a selected file from the dropDown Menu in JSP?
How to backup a selected file from the dropDown Menu in JSP?  I am trying to create a dropdown menu list for some type of files contained ina directory and upon selecting one, I'll have a click button backFile to copy the selcted
how to open one Jframe from main method call
how to open one Jframe from main method call  I have downloaded... is "playGame.java" JFrame and "game screen" appearing at the same time .thats what i...(is a JFrame) Rules.java(is a JFrame) PlayGame.java have three buttons Play - i
How to Fetch Data using dropdown option
How to Fetch Data using dropdown option   sir maine jsp pr ek login page banaya jismain branch ka option hai. main agar first dropdown main first year branch select karta hoon to first year ki sari branches ki list second drop
For every option selected from a dropdown a new textbox opens
For every option selected from a dropdown a new textbox opens  I have a dropdown with four options, each time I select an option a new text box should open below. please guide.In urgent need.   The given code displays
Populate dropdown menu from database using jsp and servlet
Populate dropdown menu from database using jsp and servlet  please i need code to populate dropdown menu from mysql database using jsp and servlet. thanks
DropDown Menu
is the problem.. for example; if i select page 1 in my dropdown menu, and click...DropDown Menu  Hello, i have a program that can view,add,delete... me draw to your my mind my program.. in my homepage which i have a dropdown
how to use dropdown list in JSP and display value in same page
how to use dropdown list in JSP and display value in same page  I... one option the value must get displayed below it in the same page... in the same page Value selected = C How can we do this in a JSP page
How to insert data from textfields into database using hibernate?
How to insert data from textfields into database using hibernate?  ...(); } This method doesn't work. I tried with quotes for textfields, without them. The setters require other parameters, not textfields. I tried to cast them
How to display content in same page while selecting fron dropdown list
How to display content in same page while selecting fron dropdown list  Thanks for your suggesstion.but Please provide me coding by using only one dropdownlist in javascript or jquery.Thanks in advance
How to display content in same page while selecting fron dropdown list
How to display content in same page while selecting fron dropdown list ...),then it want to display all records from table specific to that rollno in that same... with the request directly received from browser, but not with the events. In JSP a simple
How to create file from input values in Jframe ?
How to create file from input values in Jframe ?  hi i m doing my... an object for it.my java code is public class submit { JFrame frame; JTextArea text1; void form() { frame=new JFrame("details you have entered are"); JPanel
multiple records on same panel
multiple records on same panel  i have multiple access of records and i want to display all of them at one panel.Each time a new panel opens for a keyrecord , i want just to show records on same panel or frame, whatever u can
how to load value in dropdown list after selecting value from first dropdown list using javascript
how to load value in dropdown list after selecting value from first dropdown list using javascript  how to load value in dropdown list after selecting value from first dropdown list using javascript
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... at the JMenuBar.We define and add three dropdown menu in the menubar i.e File
Maven dependency for com.mobileia - mc-dropdown-menu version 0.1.3 is released. Learn to use mc-dropdown-menu version 0.1.3 in Maven based Java projects
-menu released The developers of   com.mobileia - mc-dropdown-menu..., the released version of  com.mobileia - mc-dropdown-menu library is 0.1.3. Developer can use this version ( com.mobileia - mc-dropdown-menu version 0.1.3
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using... should get a message with ok option and it should be sent to clients
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using... should get a message with ok option and it should be sent to clients
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using... should get a message with ok option and it should be sent to clients
How to access Contacts from gmail using LDAP in JSP dropdown list
How to access Contacts from gmail using LDAP in JSP dropdown list  HI, I am creating a JSP page in which i have to make a dropdown box, and access gmail contacts in that drop downlist using LDAP. Can any one plz help me out
Version of com.mobileia>mc-dropdown-menu dependency
List of Version of com.mobileia>mc-dropdown-menu dependency
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... three dropdown menu in the menubar i.e File Edit
open pdf file in same jsp page and the pdf file should retrieved from database
open pdf file in same jsp page and the pdf file should retrieved from database  Hai all, I need code to open a pdf file in same jsp page(browser) while click on hyperlink And the file was located in database table. Can any
how to display the selected row from the data table in model panel ??
how to display the selected row from the data table in model panel ?? ...(); return dataList; } please help me out !~!!!!! i get the model panel but the values are unable to transfer to the model panel
how to add data dynamically from database into a dropdown list in a jsp
how to add data dynamically from database into a dropdown list in a jsp  hi friends i am doing a project in jsp and oracle as my database.In my... get dynamically from the database and whenever a new person has registered his
how to create text file from jsp and provide downlode option
how to create text file from jsp and provide downlode option  HI..., r.PERMISSION FROM ROLE AS r INNER JOIN EMPLOYEEMASTER AS e ON r.ROLEID=e.ROLEID... option of this text field thanks in advanceADS_TO_REPLACE_3   Hi Friend
how read data from doc file in same formate in jsp
how read data from doc file in same formate in jsp  how we can read and display data on jsp page, from doc file with the same formatting
textfields and update - SQL
textfields and update  how can i retrieve a table from a database and put in on the textfields using jdbc?and at the same time update the items on the database
Maven Repository/Dependency: com.mobileia | mc-dropdown-menu
Maven Repository/Dependency of Group ID com.mobileia and Artifact ID mc-dropdown-menu. Latest version of com.mobileia:mc-dropdown-menu dependencies... Tutorials What is Apache Maven? How to create Maven Web Application
getting values from dropdown list
getting values from dropdown list  I am having a dropdown list which has hardcoded values ( we need it hardcoded only and will not be populated from... to the action. My action is getting called however, i am not sure how to pass
how to reset JFrame
how to reset JFrame  how to reset JFrame
dropdown
dropdown  I have a dropdown having 2 options-"Open"& "closed".When i select "open" option the related rows of data are retrieved from database and same with the other option.My database is Mysql and coding in PHP
Block edit menu option - JSP-Servlet
Block edit menu option  I am doing a jsp project. I have to control number of characters in a text area upto a limit. How can i block pasting through edit menu and pasting through short cut key [ctrl+v
Maven Dependency mc-dropdown-menu >> 0.1.2
You should include the dependency code given in this page to add Maven Dependency of com.mobileia >> mc-dropdown-menu version0.1.2 in your project
Maven Dependency mc-dropdown-menu >> 0.1.3
You should include the dependency code given in this page to add Maven Dependency of com.mobileia >> mc-dropdown-menu version0.1.3 in your project
Dynamic Dropdown Menu
Dynamic Dropdown Menu       Put records from your database in a drop down menu/list box. You can apply... to create table is open the mysql console and type the following: create table car
how can i send a mail to a particular user from a many user dropdown list in jsp
how can i send a mail to a particular user from a many user dropdown list in jsp  how can i a sent a user question to a particular person from a drop down list in jsp
TextFields
TextFields  How To create A details Of Student Using applet
JFrame
application using NetBeans IDE 6.5. I have many jframes. Whenver i click a menu in main JFrames many windows gets open. But i want all JFrames to open within Main Jframe. How can i do it. Please help me to do it. Or what else can i have
reading dropdown values from properties file in jsp
reading dropdown values from properties file in jsp  reading dropdown values from properties file in jsp
passing data from one jframe to another
passing data from one jframe to another  I have two JFrame,built by using the GUI Editor netbeans 6.9.i have to pass a data from a Jtextfield in the first Jframe to another JLabel in the other JFrame.Can you please help me,how
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than

Ads