Hi all, I am Chaitanya, I am working on a small swing application. Its a billing application. There is a button named "add to cart". When the user clicks this button the details of the current item are stored in a bean and bean is added to a ArrayList. There is another button named "show items". When the user clicks on this button an alert window (JOptionPane.showMessageDialog()) must open showing a list of items selected by the user.
I can spawn another window and show the details, but I dont want it like that. Or at least that newly spawned window must have properties like alert windows. Means, until and unless this window is closed the parent window must be disabled.
How can I do this? Thank you all in advance. Have a good day.
JOptionPane#showMessageDialog accepts an Object message. Because of this, you can pass any visual component as a message too, not just text.
In your case, you will need to convert your POJO list to a corresponding visual type. JList or JTable or something else depending on your requirement.
1) Take your POJO list
2) Build visual component from the list
3) Invoke JOptionPane#showMessageDialog passing this visual component as the "message"
JOptionPane is smart enough to display an array by showing each element of the array on its own line, and is also smart enough to use the toString() of the array element for the displayed text.
Hi all, I tried what Mr. Maneesh said. It worked fine. But there is a problem with the button. Its not getting displayed in the JTable. Some id javax.swing.JButton[0,0,0x0,......] is getting printed. I'm unable to get a visual component.