Solved

JOptionPane.showOptionDialog()

Posted on 2004-04-28
8
749 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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
 
LVL 37

Accepted Solution

by:
zzynx earned 75 total points
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
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
Comment Utility
>> Adding/ removing the component could be costly.
???
Adding/removing one simple component?
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
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
Comment Utility
Thanks for accepting.
This keeps us answering your future questions too.
:°)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now