sir As ur Source Code i have Load course names from Access Database in to JComboBox but now I want to do ,when i select Course name from Jcombobox i want to display appropriate records relate with taht course on combobox item changed event. eg when i select MCA the fees ,course type will automaticall displayed in the JTextField.
plz Help Me Sir.
April 9, 2010 at 3:30 PM
Hi Friend,
Try the following code:
import java.sql.*;
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("Branch");
final JComboBox jc=new JComboBox();
JLabel lbl2 = new JLabel("Duration");
final JTextField jt1=new JTextField(15);
JLabel lbl3 = new JLabel("Fees");
final JTextField jt2=new JTextField(15);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:access","","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select name from course");
jc.addItem("Select");
while(rs.next()){
jc.addItem(rs.getString("name"));
}
}
catch(Exception e){}
lbl1.setBounds(100,120,70,20);
lbl2.setBounds(100,150,70,20);
lbl3.setBounds(100,180,70,20);
jc.setBounds(170,120,100,20);
jt1.setBounds(170,150,100,20);
jt2.setBounds(170,180,100,20);
f.add(lbl1);
f.add(lbl2);
f.add(lbl3);
f.add(jt1);
f.add(jt2);
f.add(jc);
f.setSize(1000,1000);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jc.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ItemSelectable is = (ItemSelectable)e.getSource();
String st= selectedString(is);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:access","","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from course where name='"+st+"'");
int duration=0;
int fees=0;
while(rs.next()){
duration=rs.getInt("duration");
fees=rs.getInt("fees");
}
jt1.setText(Integer.toString(duration));
jt2.setText(Integer.toString(fees));
}
catch(Exception ex){}
}
});
}
static private String selectedString(ItemSelectable is) {
Object selected[] = is.getSelectedObjects();
return ((selected.length == 0) ? "null" : (String)selected[0]);
}
}
Thanks
Related Tutorials/Questions & Answers:
Link To Database with JComboBox - Java BeginnersLink To
Database with JComboBox sir As ur Source Code i have Load course names from Access
Database in to
JComboBox but now I want to do ,when i select Course name from
Jcombobox i want to display appropriate records relate
jComboBox with databasejComboBox with database Hello friends,
I have created three JComboBoxes. first two of them get list from string. However I select these two... my
database. But in my code its only get data from first item which
Advertisements
Help on database and JComboBoxHelp on
database and JComboBox I want to select from the
JComboBox and when click onto the "search" button, the selected category (example "new york... the things from
database How to store JComboBox item into database How to store
JComboBox item into
database import... DefaultComboBoxModel(labels);
final JPanel TypeTF = new JPanel();
JComboBox comboBox1 = new
JComboBox(model);
comboBox1.setEditable(false
Database values in JComboBoxDatabase values in
JComboBox
In this section, you will learn how to display values in
JComboBox from
database. For this, we have allowed the user to enter... the
database will get
displayed on the ComboBox. If there will be no data
binding jComboBox to mysql database - Swing AWTbinding
jComboBox to mysql database I am using netbeans 6.5
How to populate
jComboBox with data of specific column of mysql
database table?
I...){
e.printStackTrace();
}
JComboBox comboTypesList = new
JComboBoxJComboBox 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 have
jcombobox on Jframe form of IDE. In which the values are to be loaded from MySql
Database. My problem is that i want to load content of the jtable whenever i change the selected item in
JComboBox.
Thank you.
(adsbygoogle
JComboBoxJComboBox 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
jComboBoxjComboBox 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
jcomboboxjcombobox 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
JcomboboxJcombobox 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 devices and i also made a refresh button.when i click on the refresh button i
linklink how can we give hyperlinks on data retrieved from the
database and when a particular option is clicked it should be saved in another
database and details related to that
link should be diaplay and stored in the
database linklink hey frnds can anyone plz tell me how can i store my videos as
link in my
database and can retrive the video using servlet by clicking on to that
link .it may be confusing sorry about that and if someone can than plz help me
link the
link the table is displayed and other links were hidden if i want to click the next
link i have to refresh the page instead i want to do is when i click the
link the table should display and again when i click the
link the table should
LINKLINK Thank you friend.cant we use single click instead of double click and also for four
link u has given the example but i have 14 links in that case wat i should do
linklink Hi Shruti
Step1 :First thing you need to do is fetch the value from
database and save it in a variable for ex. temp and put it in between a href tag as :
Step2 : Use a id to select this using JavaScript or jQuery
LINKLINK I have four links which
link to a table,if i click one
link... i want to ask is when i click the
link the table is displayed and other links were hidden if i want to click the next
link i have to refresh the page instead i
issue on jcomboboxissue 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
JComboBox with AccessDatabase - Java BeginnersJComboBox with AccessDatabase Hello Sir I have Created Course... on Student Admission Form
when I select Course Name from
JComboBox on Student...");
JComboBox combo1=new
JComboBox();
JComboBox combo2=new
JComboBox About jcombobox - Swing AWTAbout jcombobox Hi all,
I am new to this forum.
Can we do auto suggest
jcombobox in swing? If yes is there any jar file for that or any code... JTextField tf;
private final
JComboBox combo = new
JComboBox();
private
DatabaseDatabase How to represent data from
database in a tree?
Please visit the following
link:
Retrieve data from
database in tree using Java Swing
JComboBox Event Handling - Java BeginnersJComboBox Event Handling Hi,
I have problem with event handling here.There are Two
JComboBox and a JTextField.When I select an item in first... Compare extends JFrame implements ItemListener
{
JComboBox combo,lcombo
Link to a websiteLink to a website I have created a mobile application.Now I want to insert a
link to a website so that when mobile user selects that
link he is directed to that website
Hypertext linkHypertext link hii,
What is a Hypertext
link?
hello,ADS_TO_REPLACE_1
A Hypertext
link is a special tag that links one page to another page or resource. If you click the
link, the browser jumps to the
link's HTML LinkHTML Link How do I create a
link that opens a new window
Hypertext linkHypertext link hello,,
What is a Hypertext
link?
hii,ADS_TO_REPLACE_1
A hypertext
link is a special text that perform the linkage between two web page.
<a href="www.roseindia.net">roseindia site</a>
position of a link position of a
link the table appears at the bottom i want it to be display at the top pls help me.Each
link if i click it should display in the same position
attaching a linkattaching a link I want the program code for , creating an application form and it is attached to our code, by clicking on this
link, the form should be open
JComboBox Display Problem - Java BeginnersJComboBox Display Problem I am create one program that contain two...,ItemListener
{
Container c;
JLabel lblstart,lblend;
JComboBox cmbstart...");
lblend=new JLabel("End Date");
cmbstart=new
JComboBox();
cmbend=new
Link on ImageLink on Image HTML
link question mark Image
can anyone please suggest how can i
link the question mark image in HTML?
<p>
<a class="mainLinks" href="#">Currency Converter <img src
Retrieve data by clicking a linkRetrieve data by clicking a link In a page there are 5 links.Every
link has a hidden value. According to that hidden value data should be retrieved from the
database and data should be displayed in a new page.How to do it?Please
mfmailComposeViewController linkmfmailComposeViewController link Is there any way to get a hyperlink on email text using mfmailComposeViewController in my iPhone application?
To get
link on the text, you need to make it HTML enable
Create a JComboBox Component in Java
Create a
JComboBox Component in Java
In this section, you will learn about the
JComboBox Component
of swing in java. The
JComboBox is used to display drop-down list