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

Ads

 
 

Share on Google+Share on Google+

vikas pandey
How to open textfields in the the same panel of the jframe by selcting from dropdown menu option ...
2 Answer(s)      5 years and 4 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);
  }
}
Ads
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......


Ads









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
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
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 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
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
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 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
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
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 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 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 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
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 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
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 create text file from jsp and provide downlode option
how to create text file from jsp and provide downlode option  HI... FROM ROLE AS r INNER JOIN EMPLOYEEMASTER AS e ON r.ROLEID=e.ROLEID WHERE... of this page in text file and also downlode option of this text field thanks
Version of com.mobileia>mc-dropdown-menu dependency
List of Version of com.mobileia>mc-dropdown-menu dependency

Ads

 
Advertisement null

Ads