Solved

JOptionPane.showOptionDialog()

Posted on 2004-04-28
8
755 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
[X]
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
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

695 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