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:
Advertisements
how to open one Jframe from main method callhow 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 optionHow 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
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 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 panelmultiple 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
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
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
textfields and update - SQLtextfields 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
getting values from dropdown listgetting 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
dropdowndropdown 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-ServletBlock 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
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
TextFieldsTextFields
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
passing data from one jframe to anotherpassing 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 JFramehow 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 JFramehow 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