简体   繁体   中英

Java Checkbox List in Netbeans

I have to design an application which handles customer orders. The GUI has tabs, one for the customer and one for the admin. In the customer tab, he has the possibility of submitting an order, by chosing the products from the product list, each having a checkbox in front of them and a text field in which the quantity will be specified.

I am using the netbeans gui editor for the design and I am a bit stuck as the code cannot be modified. I cannot create the product list dynamically (so to create a line for each product in the product array list, and on each line to put the checkbox and the textfield) or at least I don't know how to.

My question is - is there any way of dynamically creating such a list (checkbox + label with the product name + textfield which waits for the quantity) or is there an alternative to my idea ?

Sounds like you need to use a JTable for your list of Products and Quantities. In the NetBeans GUI editor you will only be able to place the JTable on the panel you are designing. After that you need to define a 'Model' for your table which will hold the data you are entering. See the official Oracle Java tutorial on How to Use Tables .

Of course there are lots of other use cases that would fit your requirements, but your design sounds fine. The checkbox is probably superfluous though, as entering a quantity against a product should be enough to indicate that the customer has chosen that Product. If your list of Products gets too long, though, you might want to re-visit this design. Perhaps the table could have 2 coulmns, the first one being a combo-box list of Products, and the second column has the quantity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM