Home Answers Viewqa Swing-AWT How to open textfields in the the same panel of the jframe by selcting from dropdown menu option ...

 
 


vikas pandey
How to open textfields in the the same panel of the jframe by selcting from dropdown menu option ...
2 Answer(s)      10 months ago
Posted in : Swing AWT

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 Pages:
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
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
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
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
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
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
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
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
dropdown
dropdown  how to select an item from the dropdownlist when we load...; <select name="sel" id="sel" onchange="sel();" > <option value="C">C</option> <option value="JAVA">JAVA</option> <option value
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
Dynamic Dropdown Menu
Dynamic Dropdown Menu       Put records from your database in a drop down menu/list box. You can apply... is open the mysql console and type the following: create table car_list (c_id int
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
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
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
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
textfields and update - SQL
textfields and update  how can i put retrieved table from a database to the textfields using jdbc?and at the same time update the items on the database..   Hello Friend As per ur 1st Q: Read the data from
Menu
. "Select from this menu" 1. Array 2. Stack 3. Queue. 4. Exit. If users press 1.... All the will give the user. Same as above. If user press 2. Stack, then it will perform Insertion and deletion from the top of the end. Welcome in Stack
TextFields
TextFields  How To create A details Of Student Using applet
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
JSP Dependent Drop Down Menu
to guide me in creating a drop down menu, where the first menu affects the second menu and it's selection. So in my database I have a category table that has a ID, parentID, and name. parentID is a FK to the PK ID within the same table. Can
menu with scrollbar
*; public class menu extends JFrame{ private JPanel panel; public menu... 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
Dropdown menus onchange atribute
Dropdown menus onchange atribute  Can I know how do we get the drop... from database and store it into dropdown list. On selecting the value from the first dropdown, the values will get stored into another dropdown from the database
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
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
DropDown list
DropDown list  how to get mysql database values into dropdown usign... values into dropdown list. 1)country.jsp: <%@page import="java.sql.*"%>...;option value="none">Select</option> <% Class.forName
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
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
jframe
jframe  Create a JFrame for the Summervale Resort. Allow the user to view the information about different rooms available, dining options and activities offered. Include at least two options in each menu and display appropriate
select option value
select option value  if i select a value of any drop down then that value should be used in a select query of the next dropdown in jsp on same page????   Here is an example of dependent dropdown box in JSP. The values
Select DropDown Default
i want to do is if the user select the "View ALL Page" from the dropdown menu... of the record, in my jsp page i have a one dropdown menu where the user can choose, i.e if the user select PAGE 1 in the dropdown menu, it will display all
jframe
jframe  how to create a jframe.provide me the java code pls
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
Ajax Dropdown
Ajax Dropdown  hi I have One Dropdown that contains 2 options assume A and B,if i select A option then samepage one more Dropdown is their it should... display should be in german but, values internally work same
. Display JavaScript dropdown selected value
. Display JavaScript dropdown selected value  How to get the selected value from dropdown box? I am using javascript.   <html> <...="dropdown" onchange="selectDropdown()"> <option value="India" >India<
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
DropDown in ajax+jsp
DropDown in ajax+jsp  I have four dropdown if i select first dd then only corresponding values must be there in 2nd dd,same with 3 and 4...; <option value="none">Select</option> <% Class.forName
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
DropDown Department Login
is having the departments in the same table. Bcoz as per the SQL Query select * from...DropDown Department Login  Hi all, I am doing a project using JSP... the departments. Now, my intention is to select the department from the drop
Alphabetical DropDown Menu In JSP
Alphabetical DropDown Menu In JSP   ... Button then application will delete the User information from database... > <select name="userid" id="userid"> <option
jsp drop down-- select Option
code populate the second dropdown on selecting the value from the first...jsp drop down-- select Option  how to get drop down populated...;nbsp;</td> <select name="sel"><option value=""><---Select
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
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
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.