Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to write a custom alert window?  RSS feed

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I do this?


What's wrong with the solution you mentioned, JOptionPane.showMessageDialog(...) ?
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mr. Darryl, I'm unable to understand how to do it with message dialog.

JOptionPane.showMessageDialog("this", ::The Array List must go here:: );

how to include the following code there

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mr. Maneesh, I ll try and let you know.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl,
The OP modified/clarified his requirement as a code comment in the second post
//this must be printed on the pane with a button besides every row to delete the row if the user mistakenly enters wrong data.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, missed that. Thanks for pointing it out.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Whats the problem here? Thank you all in advance.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out Rob Camick's Table Button Column.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have checked it, some what hard to understand.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!