?
Solved

JOptionPane.showOptionDialog()

Posted on 2004-04-28
8
Medium Priority
?
757 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 37

Accepted Solution

by:
zzynx earned 225 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

771 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