File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Netbeans Combobox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Netbeans Combobox" Watch "Netbeans Combobox" New topic
Author

Netbeans Combobox

Bartosz Emas
Greenhorn

Joined: Dec 27, 2013
Posts: 4
Hello All ! I am designing a very simple program in Netbeans. What I wish to achieve is when I select item from a Jcombobox for example, Item 1, in a JtextField will appear an integer. Is there any simple way to achieve this ? thank you for any response.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Welcome to the Ranch

Have you been through the Java Tutorials? About 11 pages down, you will find a page about combo boxes.
Bartosz Emas
Greenhorn

Joined: Dec 27, 2013
Posts: 4
I have went through it, however I did not find appropriate solution. Thank you for quick respond!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
It is exactly the same whether you use NetBeans, text editors, or whatever.
Note that a combo box implements ActionListener itself, but the API says not to use its own action performed method,
Bartosz Emas
Greenhorn

Joined: Dec 27, 2013
Posts: 4
I have created in NetBeans JForm and appended a few jComboBoxes and jTextFields. I have found the following code on the internet:


However when I am typing into my program it does not work.

Any idea where this code should go ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Yes, I can tell you where that code should go: recycle bin
Always tell us where you get code or quotes from, in case there is a copyright problem or similar. Always use code tags, which I have added for you, and you can see how much better it looks

I don't think flow layout is any good. I also don't like extending frames; that creates a class which tries to combine display (=V in MVC) and data (M) in one class. Did you notice the non‑OO design in the Listener? A load of if‑elses which will cease to work correctly if you add "item3" to the combo box, or write anything else not it is editable. And the assumption that the source is a combo box. It may be very old code; it has not been necessary to use getContentPane().add(...) for over 9 years. You can simply write add(...).

Please tell us what is going wrong. When I executed the code you posted, it put 30 or 40 in the text field, but failed to do anything when I edited the combo box, which is exactly what I would have expected. The code I posted yesterday would have put 1 2 3 or 4 in the text area if you had expanded it to a full class.
 
jQuery in Action, 2nd edition
 
subject: Netbeans Combobox