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 solution. tahnks in advance.

View Answers

December 18, 2012 at 12:16 PM

Here is an example that shows the selected value from the jcombobox to textfield.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class  SelectComboboxValue{

    public static void main(String[] args) throws Exception{
        JFrame f=new JFrame();
        f.setLayout(null);
        JLabel lab=new JLabel("Select Programming Language: ");
        final JComboBox combo=new JComboBox();
        final JTextField text=new JTextField(20);
        combo.addItem("--Select--");
           combo.addItem("Java");
           combo.addItem("C/C++");
           combo.addItem(".NET");
           combo.addItem("Perl");


        ActionListener actionListener = new ActionListener(){
        public void actionPerformed(ActionEvent actionEvent) {
        ItemSelectable is = (ItemSelectable)actionEvent.getSource();
        String st=selectedString(is);
        text.setText(st);
        }
    };
       combo.addActionListener(actionListener);
        lab.setBounds(20,20,200,20);
        combo.setBounds(200,20,80,20);
        text.setBounds(280,20,100,20);
        f.add(lab);
        f.add(combo);
        f.add(text);

        f.setVisible(true);
        f.setSize(400,120);
    }
    static private String selectedString(ItemSelectable is) {
    Object selected[] = is.getSelectedObjects();
    return ((selected.length == 0) ? "null" : (String)selected[0]);
  } 
}









Related Tutorials/Questions & Answers:
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
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
Advertisements
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 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. (adsbygoogle... JLabel("Select"); final JComboBox combo=new JComboBox
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 devices and i also made a refresh button.when i click on the refresh button i
jComboBox with database
jComboBox with database  Hello friends, I have created three JComboBoxes. first two of them get list from string. However I select these two comboboxes, the third combobox automatically retrieve data of a particular column from
JComboBox on JRadioButton - Java Beginners
JComboBox on JRadioButton  How to add JComboBox on Jpanel ,Give Me Sample Code
JFormattedTextField issue
to place a JFormattedTextField inside a JComboBox. The JComboBox is in one of the JTable columns. The JComboBox holds a list of item and I also want the JComboBox... that JFormattedTextField inside the JComboBox. Thanks for help! Morongo
Help on database and JComboBox
Help on database and JComboBox  I want to select from the JComboBox and when click onto the "search" button, the selected category (example "new york") all the each new york picture and detail will be seen. But how to grab
JComboBox with AccessDatabase - Java Beginners
JComboBox 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 AWT
About 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
JComboBox Event Handling - Java Beginners
JComboBox 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
jdialogbox issue.
jdialogbox issue.  i have one button.when clicked on it has to show a dialog box.but even click on it several times it has to open dialog box only once. if it is already not opened atleast once,then only it has to open dialog
JTABLE Issue
to go back for another search. Now issue is -- when I put some input data
Issue with Javascript
Issue with Javascript  Hi I created arrays in javascript in following way var myimages= new Array(); myimages[0]="iphone_pushups.png"; myimages[1]= "cricket.png"; myimages[2]= "july.png"; myimages[3]= "matrix.png
problem with addactionlistener on JComboBox - Java Beginners
[] = { "A", "B", "C"}; JFrame frame = new JFrame(); JComboBox combo = new JComboBox(st); frame.add(combo); ActionListener actionListener = new
Changing JLabel with a jcombobox - Java Beginners
listener event of JComboBox put JLabel.setText("Put yourtext here
Link To Database with JComboBox - Java Beginners
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..."); final JComboBox jc=new JComboBox(); JLabel lbl2 = new JLabel("Duration"); final
JComboBox Display Problem - Java Beginners
JComboBox 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
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
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
Database values in JComboBox
Database 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... JFrame(); f.getContentPane().setLayout(null); final JComboBox combo = new
easy way to make a JCombobox look like a JTextField?
easy way to make a JCombobox look like a JTextField?  Is there a good(and easy) way to make a JCombobox look like a JTextField? By this I mean there should not be a dropdown button, but when the user enters something it should
binding jComboBox to mysql database - Swing AWT
binding 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
How to Add JComboBox on JPanel - Java Beginners
How to Add JComboBox on JPanel  How to Add JComboBox on JPanel D:\java>javac ViewElements.java ViewElements.java:181: expected...); JLabel lbl4=new JLabel("Branch"); final JComboBox jc=new JComboBox(); jc.addItem
Decimal Format Issue Java
Decimal Format Issue Java  Decimal Format Issue Java
ModuleNotFoundError: No module named 'issue'
ModuleNotFoundError: No module named 'issue'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'issue' How to remove the ModuleNotFoundError: No module named 'issue'
ModuleNotFoundError: No module named 'issue'
ModuleNotFoundError: No module named 'issue'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'issue' How to remove the ModuleNotFoundError: No module named 'issue'
semantic issue xcode 4.2
semantic issue xcode 4.2  I have updated xcode 4.0 to 4.2 .. but once i open any application in this new version of xcode ..it throws lots of semantic issue. Can anyone please explain why it occurs and how to resolve
Resultset Issue in SQL
Resultset Issue in SQL  when i call rs.next() in my code it is returning false, though im having valid query to execute and fetch a row from database.how can i resolve this issue. My code is: SELECT JOBDESCRIPTION,CATEGORY
Reloading issue in jsp
Reloading issue in jsp  I wrote one jsp page with one submit button. If we click on button it will execute business logic, but I want to stop reloading page if user refreshed the link. how we do
Issue in JSF and Richfaces.
Issue in JSF and Richfaces.  Hi,I am with a issue in JSF and Richfaces.I have one add user page.In which i have fields Firstname,LastName,SecretID(which has Validate/suggest as links beside tat) ,Email address,city,state,country
Login issue using Servlet
Login issue using Servlet  Hi all, I need a code for login using servlet where in I want to check and validate user name and password from database also I want to check candidate's class (for ex. FY, SY, TY) if candidate's class
Read Issue itext
Read Issue itext  Hello, I m using itext to read data from pdf file.. Right now i m reading page wise data,but i want to extract data on each line In variable whole page data there... so i want to read data line by line so
Grid rows delete issue
on onchange of dropdown then because of rows indexing issue,they can't get middle row
Read Issue itext
Read Issue itext  Hello, I m using itext to read data from pdf file.. Right now i m reading page wise data,but i want to extract data on each line In variable whole page data there... so i want to read data line by line so
maven subversion issue
maven subversion issue   m doing work on maven and subversion i have created a maven project now i want to point it to my repository(created by svn tortoise) i read that for this i have to change in pom.xml file from this site
jquery issue plese help
jquery issue plese help  Im am trying to Change the background color of the dashboard to black with an opacity of 0.6 Change the opacity of the images in the dashboard to 0.5 before the dashboard slides out. Change the opacity
Initializing Integer Variable issue?
Initializing Integer Variable issue?  My program is supposed to take a phrase like you'd see on a TV commercial, for example: "Call 1-800-GETLOAN now to..." then take that phrase and convert it to its actual phone number. My
Solving java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean issue
Solving java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean issue  Solving java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean issue In my Spring
JComboBox Insert Edited Value Into Table
JComboBox Insert Edited Value Into Table In this section we will read about how to make JComboBox an editable and then how to insert the new edited value... in to insert an editable value of JComboBox into a table. We will use an Java editor
Add Items in JComboBox from Access Database - Java Beginners
Add Items in JComboBox from Access Database  Heelo Sir I want To add ittem in JComboBox which is stored in Access Database. plz Help Me Sir... records in to my JComboBox.   Hi Friend, Try the following code
How to store JComboBox selected Item into Ms Access Database - Java Beginners
How to store JComboBox selected Item into Ms Access Database  How to store JComboBox selected Item into Ms Access Database.  Hi Friend..."); f.getContentPane().setLayout(null); JLabel lbl1=new JLabel("Branch"); final JComboBox jc
How to save JCombobox Selected Item in to Access Database - Java Beginners
How to save JCombobox Selected Item in to Access Database  How to save JCombobox Selected Item in to Access Database  Hi Friend, Try...().setLayout(null); JLabel lbl1=new JLabel("Branch"); final JComboBox jc=new
Load Coursenames from MS Acess Database to JComboBox - Java Beginners
"); final JComboBox jc=new JComboBox(); try{ Class.forName
navigation between panels when item is selected from jcombobox - Swing AWT
on JComboBox in Java visit to : http://www.roseindia.net/java/example/java/swing
ModuleNotFoundError: No module named 'issue-pub'
ModuleNotFoundError: No module named 'issue-pub'  Hi, My Python... 'issue-pub' How to remove the ModuleNotFoundError: No module named 'issue... have to install padas library. You can install issue-pub python with following
ModuleNotFoundError: No module named 'jira-issue'
ModuleNotFoundError: No module named 'jira-issue'  Hi, My Python... 'jira-issue' How to remove the ModuleNotFoundError: No module named 'jira-issue' error? Thanks   Hi, In your python environment you

Ads