Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

How to write a custom alert window?

 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mr. Maneesh, I ll try and let you know.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops, missed that. Thanks for pointing it out.
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out Rob Camick's Table Button Column.
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have checked it, some what hard to understand.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic