Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JOptionPane.showOptionDialog()

Posted on 2004-04-28
8
753 Views
Last Modified: 2011-08-18
hi all...

this question is regasrding swings....

wut i wana do is...
i want to show a messagebox (JOptionPane.showOptionDialog())
with two buttons (OK,DETAILS)
i wana show some errors and if user clicks DETAILS an hidden window should pop up at bottom of these button and will show appropiate details.

iam unable to think how to do this
can  u ppl guide....
right now when user click DETAILS, then current error window disappears n i show new messagebox with one button(OK)

but actually i dont want tht original messagebox to go click on DETAILS should enlarge tht messagebox showing details
and second click should hide it

you must have noticed same in windows as in VB etc its easy

can u pls guide me how can this be done using java

if u r not able to get the question i can explain in more detial

Regards
Harpreet
0
Comment
Question by:Harpreet79
  • 5
  • 2
8 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 10936949
This is a rough little snippet that does what you want. Up to you to make it nicer.

        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(new JLabel("Some error message"), BorderLayout.NORTH);
        JTextArea textArea = new JTextArea("Details about the error\n\rMore Details...");
        boolean detailsVisible = false;
        Object[] options = { "OK", "DETAILS" };
        int choice = 1;
        while (choice==1) {
            choice = JOptionPane.showOptionDialog(null, panel, "Title",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1] ) ;
            if (choice==1) {
                if (detailsVisible)
                    panel.remove(textArea);
                else
                    panel.add(textArea, BorderLayout.CENTER);
                detailsVisible = !detailsVisible;
            }
        }
0
 

Author Comment

by:Harpreet79
ID: 10937177
hi buddy
i have tried the example it is much better than wut i was doing
but a little more effort is required actually here pressing DETAILS show the JTextField message under the previous message
right na!!!!!!

but i wana tht below the 2 button the details part should be shown
means how can i expand the box from bottom to show details there

if u have some example for tht pls let me know

thanx
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10937765
>> but i wana tht below the 2 button the details part should be shown
Than you'll need to completely make your own panel.
Using JOptionPane doesn't allow you to place something under that buttons.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 37

Accepted Solution

by:
zzynx earned 75 total points
ID: 10937790
That shouldn't be too difficult.
The base idea is in the code I gave you:
add/remove an extra component in your panel whenever you press <Details>
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10938117
Adding/ removing the component could be costly. What you could do is - keep a text-area for displaying the details, and make it invisible/ visible based on whether the user wishes to see the details or not. When you make it invisible, decrease the height of your container and when you make it visible, increase it back to its original height.

Mayank.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10938149
>> Adding/ removing the component could be costly.
???
Adding/removing one simple component?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10938178
Well, just that adding/ removing a text-area is still expensive than just making it visible/ invisible.... nothing else ;-)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10938238
Thanks for accepting.
This keeps us answering your future questions too.
:°)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 45
Android development question 2 54
login form jsp example 2 37
java imports not found 4 26
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question