The Artima Developer Community
Sponsored Link

Java Answers Forum
Importing value in textbox when an item is selected in the combobox

1 reply on 1 page. Most recent reply: May 29, 2007 1:35 AM by Kiran Kumar

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
khan Ruqsana

Posts: 6
Nickname: gudiyaa
Registered: Nov, 2006

Importing value in textbox when an item is selected in the combobox Posted: May 26, 2007 12:31 AM
Reply to this message Reply
Advertisement
hiii every one.... i have a small problem i would like to get the item in the textbox which is selected in the combobox. means when ever i select the item in the combobox it should get the value in the textbox. plzzz can neone help...


Kiran Kumar

Posts: 12
Nickname: k3
Registered: May, 2007

Re: Importing value in textbox when an item is selected in the combobox Posted: May 29, 2007 1:35 AM
Reply to this message Reply
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ComboProblem extends JFrame{

private JComboBox myCombo;
private JTextField myText;

ComboProblem(){
super("C O M B O");

myText = new JTextField();
add( BorderLayout.CENTER, myText);

Object []items = { "Select a Language", "Java", "C++", "SmallTalk", "Python" };
myCombo = new JComboBox( items );
myCombo.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent e ){
Object obj = ((JComboBox)e.getSource()).getSelectedItem();
myText.setText( obj.toString() );
}
});
add( BorderLayout.NORTH, myCombo );

setDefaultCloseOperation( EXIT_ON_CLOSE );
setBounds( 10, 20, 300, 100 );
setVisible( true );
}
public static void main(String[] args) {
new ComboProblem();
}

}

Flat View: This topic has 1 reply on 1 page
Topic: Importing value in textbox when an item is selected in the combobox Previous Topic   Next Topic Topic: Data Service 2.0.0

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use