Forums Register Login

Netbeans Combobox

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Welcome to the Ranch

Have you been through the Java Tutorials? About 11 pages down, you will find a page about combo boxes.
+Pie Number of slices to send: Send
I have went through it, however I did not find appropriate solution. Thank you for quick respond!!
+Pie Number of slices to send: Send
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,
+Pie Number of slices to send: Send
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 ?
+Pie Number of slices to send: Send
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.
Get out of my mind! Look! A tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 5170 times.
Similar Threads
Question from NickyEng
How to create a List from an Array?
best IDEs, editors for Groovy/Grails?
Netbean project demo
How to delete items from the cart through jsf
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:44:30.