January 10, 2009 at 12:52 AM
Hi friend,
code to help in solving the problem :
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
public class JComboBoxExample extends JPanel {
JLabel jlbPicture;
public JComboBoxExample() {
String[] comboTypes = { "Numbers", "Alphabets", "Symbols"};
Vector<Object> vector = new Vector<Object>();
Connection con = null;
String url = "jdbc:
mysql://localhost:3306/";;
String db = "userdetails";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db, user, pass);
try{
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM userform");
while (res.next()) {
vector.add(res.getString("username"));
}
con.close();
}
catch (SQLException s){
System.out.println("SQL code does not execute.");
}
}
catch (Exception e){
e.printStackTrace();
}
JComboBox comboTypesList = new JComboBox(vector);
comboTypesList.setSelectedIndex(2);
comboTypesList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox jcmbType = (JComboBox)e.getSource();
String cmbType = (String)jcmbType.getSelectedItem();
jlbPicture.setIcon(new ImageIcon(""+cmbType.trim().toLowerCase() + ".jpg"));
}
});
// Set up the picture
jlbPicture = new JLabel(new ImageIcon("" +
comboTypes[comboTypesList.getSelectedIndex()] +
".jpg"));
jlbPicture.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
jlbPicture.setPreferredSize(new Dimension(177, 122+10));
// Layout the demo
setLayout(new BorderLayout());
add(comboTypesList, BorderLayout.NORTH);
add(jlbPicture, BorderLayout.SOUTH);
setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
}
public static void main(String s[]) {
JFrame frame = new JFrame("JComboBox Usage Demo");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
frame.setContentPane(new JComboBoxExample());
frame.pack();
frame.setVisible(true);
}
}
Thanks
Related Tutorials/Questions & Answers:
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... = null;
String url = "jdbc:
mysql://localhost:3306/";
String db
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 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
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
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
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
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
MYSQL DatabaseMYSQL Database Can any one brief me about how to use
MYSQL Database to store the create new
database, create tables.
Thanks.
Hi, the
MySQL database server is most popular
database server and if you want to know
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
XML parsing to Mysql databaseXML parsing to
Mysql database Can someone please post the code for parsing an XML file into
Mysql database using SAX
Create Database and tables in MySQL and tables in
MySQL Database?
Explain me step-by-step as I am beginner in
MySQL.
Thanks
Hi,
First of all you have to connect to
MySQL database through command line tool.
Connecting to
MySQL Database:
mysql -uroot -p
Here
Connecting to MYSQL Database in JavaConnecting to
MYSQL Database in Java I've tried executing the code...("
MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:
mysql://localhost/";
String dbName = "textbook";
String driver
MySql database - SQLMySql database hello sir,
i am trying to write a code which should... to retrieve the data from Ms-access then you create a
database , table and create a connection with this. Then you retrieve the data from the
database.
Thanks
Setup MySQL DatabaseSetup
MySQL Database
... into
MySQL database. Table created here will be used in sample application.../mysql/mysql5/Installing-
MySQL-on-Windows.shtml
Creating
Database :
You can create
Submit button to MySQL database?Submit button to
MySQL database? Need help linking html code to
mysql database
<html>
<head>
<meta http-equiv="Content-Type...").newInstance();
Connection connection = DriverManager.getConnection("jdbc:
mysql Submit button to MySQL database?Submit button to
MySQL database? Need help linking html code to
mysql database
<html>
<head>
<meta http-equiv="Content-Type...").newInstance();
Connection connection = DriverManager.getConnection("jdbc:
mysql Backup MySQL Database - JSP-ServletBackup
MySQL Database
Database Sir I have been reading Rose's india tutorial "Using
MySQL Database with JSP/Servlet". In the Tutorial you have shown an example of backing up the
database. When I tried to backup
database database connectivity using mysqldatabase connectivity using mysql java file: eg1.java
package eg...[]) throws SQLException
{
try
{
String connectionURL = "jdbc:
mysql... seconds)
I am using Netbeans 5.5,
mysql server 5.0, to get data from table
Error with LogIn with mysql databaseError with LogIn with
mysql database Hi,
I have followed steps from your tutorial titled SpringMVClogin with
database. I am not using Jetty, as I have Tomcat as my server using Eclipse IDE. When I run the program I get a Http
MySQL Create Database MySQL Create
Database
... to create the
database on
MySQL
Server.
MySQL Database server is one of the very... of the
database server.
MySQL comes with the easy to use the command line tool through
retrieve data from mysql databaseretrieve data from
mysql database hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from
mysql database using php.... below my code is that..
<html>
<head>
Creating a Database in MySQL
Creating a
Database in
MySQL
After establishing the connection with
MySQL
database by using.... In this example we are going to create a
database by
MySQL and with the help
MySQL Database Training
MySQL Database Training
MySQL
Training Course Objectives
How...
MySQL data with SQL.
How to create a simple
MySQL
database Table
Image upload in mysql database using jsp servletImage upload in
mysql database using jsp servlet Hello, I need code to insert image in
mysql database, I have seen the code which is already in your portal but it is not inserting image into
database it save in the folder
Problem in uploading image to to mysql database the record to
mysql database.
heres my code...
index.jsp
<%@ page...Problem in uploading image to to
mysql database Hi, need some help... be save in the
database. and the image will also save in the desired folder. i
Problem in uploading image to to mysql database the record to
mysql database.
heres my code...
index.jsp
<%@ page language...Problem in uploading image to to
mysql database Hi, need some help... be save in the
database. and the image will also save in the desired folder. i