i want to create JFrame with multiple panel each panel displaying some information from database (say product_id and description ) and each frame have a button(add to cart) which will add the information from that panel to cart table in my database how will i implement this?
2 Answers
I would try to simply things by using a JTable to display such data, with each column displaying a database field. I'd add an extra column, say a Boolean column that displays as a check box, and then assess the state of that column when needing to decide which to add to a cart.
Edit You ask:
how will i know how much quantity of that product is selected,
Then add a quantity field as well, perhaps one that uses a JSpinner as its editor.
and also i am thinking to add image of that product also can i do it in Jtables
Absolutely. It knows how to display ImageIcons for instance. Please have a look at my answer to another question for an example.

- 1
- 1

- 283,665
- 25
- 256
- 373
-
how will i know how much quantity of that product is selected and also i am thinking to add image of that product also can i do it in Jtables – user3430383 Apr 06 '14 at 18:21
-
how can i add checkbox in a Jtable? – user3430383 Apr 06 '14 at 18:25
-
@user3430383: if using a DefaultTableModel, make sure that the column of interest, the one that is to display a check box is of Boolean type. Then override the model's `getColumnClass(int columnIndex)` to return `Boolean.class`. – Hovercraft Full Of Eels Apr 06 '14 at 18:26
You should create a JPanel (called PanelButton) which contents [Add to cart] button.
In other JPanels, you add PanelButton.
So, by this way, you can reuse your button without implement a lot of [Add to cart] button for each panel.

- 585
- 1
- 5
- 16
-
1`you can reuse your button` You can't reuse a button. A Swing component can only be added to a single container. You can create an ActionListener and share the ActionListener for all buttons. – camickr Apr 06 '14 at 18:31
-
-
@HovercraftFullOfEels, yes, ActionListeners should be a thing of the past :) – camickr Apr 06 '14 at 18:53