How to Add JComboBox on JPanel

Ads
 

How to Add JComboBox on JPanel

How to Add JComboBox on JPanel
D:\java>javac ViewElements.java
ViewElements.java:181: <identifier> expected
jc.addItem("France");
^
ViewElements.java:182: <identifier> expected
jc.addItem("Germany");
^
2 errors
View Answers

April 8, 2010 at 3:39 PM

Hi Friend,

Try the following code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SwingFrame{
public static void main(String[] args) throws Exception{
SwingFrame sf=new SwingFrame();
}
public SwingFrame(){
JFrame f = new JFrame("Frame in Java Swing");
f.getContentPane().setLayout(null);
JLabel lbl1 = new JLabel("Name");
JTextField jt1=new JTextField(15);
JLabel lbl4=new JLabel("Branch");
final JComboBox jc=new JComboBox();
jc.addItem("Select");
jc.addItem("MCA");
jc.addItem("MBA");
jc.addItem("BE");
jc.addItem("BTech");
jc.addItem("Others");
lbl1.setBounds(100,120,70,20);
lbl4.setBounds(100,150,70,20);
jt1.setBounds(170,120,100,20);
jc.setBounds(170,150,100,20);
f.add(lbl1);
f.add(lbl4);
f.add(jt1);
f.add(jc);
f.setSize(1000,1000);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Thanks

Ads









Related Tutorials/Questions & Answers:
How to add JTable in JPanel
How to add JTable in JPanel  How to add JTable in JPanel
JComboBox on JRadioButton - Java Beginners
JComboBox on JRadioButton  How to add JComboBox on Jpanel ,Give Me Sample Code
Advertisements
How to store JComboBox item into database
How to store JComboBox item into database   import... DefaultComboBoxModel(labels); final JPanel TypeTF = new JPanel(); JComboBox...(javax.swing.SwingConstants.CENTER); jLabel1.setText("ADD NEW ITEMS"); getContentPane
How to draw in jPanel? swing/graphics Java
How to draw in jPanel? swing/graphics Java  How to draw in jPanel? (swing/graphics Java
jpanel
jpanel  hello sir, i made one jpanel inside the frame and made the button inside the panel.. wrote the only second panel code other class file.. so.......?? thanku and second question how to attach calender jar file in jtextfield using
jpanel
jpanel  hello sir, i made one jpanel inside the frame and made the button inside the panel.. wrote the only second panel code other class file.. so.......?? thanku and second question how to attach calender jar file in jtextfield using
jpanel
jpanel  hello sir, i made one jpanel inside the frame and made the button inside the panel.. wrote the only second panel code other class file.. so.......?? thanku and second question how to attach calender jar file in jtextfield using
jpanel
jpanel  hello sir, i made one jpanel inside the frame and made the button inside the panel.. wrote the only second panel code other class file.. so.......?? thanku and second question how to attach calender jar file in jtextfield using
Jcombobox
Jcombobox  Hii, I am doing my final year project and i am using java swing as a front end.I have used Jcombobox for displaying my on bluetooth... want updated list of on devices in that same combobox.I cant understand how to do
JComboBox
JComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
jComboBox
jComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
How to add
How to add   Hi, I want to make a website which will recommend users books according to the genre selected by them. I am using PHP, JavaScript and mySQL. The problem is that there will me almost more than 100 books
JComboBox
JComboBox  I have jcombobox. In which tha values are loaded from MySql Database. My problem is that i want to load content of the jtable whenever i change the selected item. Please some one help me to do this. Thank you
jcombobox
jcombobox  hi i have developed a form and i have jcombobox in which data is retrieved from ms access but the problem is that if we pressed the down key the last 5 data are not showed only the other data can be pressed
JComboBox
have jcombobox on Jframe form of IDE. In which the values are to be loaded from... change the selected item in JComboBox. Thank you.   import java.sql....); JLabel lab=new JLabel("Select"); final JComboBox combo=new JComboBox
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
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
how to add dynamic data
how to add dynamic data  how to add dynamic data to an existing web application
how to add mulitiple projections
how to add mulitiple projections  how to add mulitiple projections and return them
how to add a file in GZIP
how to add a file in GZIP  Hi, how to add a file in GZIP using Java.   Hi, I have found a good referral site for How to Add a file in GZIP file format using Java. http://www.roseindia.net/java/examples/io
How to add BigDecimal in Java?
How to add BigDecimal in Java?  Hi, I have two BigDecimal variables. I want to add these two values. How to add BigDecimal in Java? Thanks   Hello, I will show you how you can add two BigDecimal? Suppose you have
how to add plugins into eclipse
how to add plugins into eclipse  Hello, I have installed eclipse sdk 4.2M5 separately and tomcat server separately now i have to connect both for that i don't have server option in my eclipse and i m trying to add plugins but m
How to add dynamic table in java
How to add dynamic table in java  How to add dynamic table in java   import java.awt.*; import java.sql.*; import java.util.*; import... Vector(); Vector data = new Vector(); JPanel p=new JPanel(); try { Class.forName
how to add database in Java Applet
how to add database in Java Applet  hi every java master or Java Professional my name is vincent i'm java beginners hope u all can ,tech me how to add database in Java Applet below this code is my applet source code . thank
issue on jcombobox
issue on jcombobox  i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.only few values in the combobox need this functionality. need
How to add a bean in spring application?
How to add a bean in spring application?  Hi, How to add a bean in spring application? Thanks
how to add fields at runtime in j2me
how to add fields at runtime in j2me  How can I add fields at runtime in my form? How can I switch screens and can add fields at runtime? Thanks Dhruv

Ads