[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

JOptionPane.showOptionDialog()

Posted on 2004-04-28
8
Medium Priority
?
758 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

649 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