Solved

JDialog, OK, and CANCEL

Posted on 2000-03-23
7
1,253 Views
Last Modified: 2012-08-14
Hi:

  I'm using a JDialog and I created it as modal...after I add my components to it, how do I get it to pop up? How do I get its return result? does it automagically come with OK and CANCEL buttons or do I have to add them in myself?

Thank you,
0
Comment
Question by:jwilcox
[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
7 Comments
 
LVL 16

Accepted Solution

by:
heyhey_ earned 80 total points
ID: 2651020
1) use dialog.setVisible(true);
2) you have to add the buttons yourself
3) add ActionListeners to these buttons and set some dialog field on button press. than you can check that field later from your main app.
0
 
LVL 1

Author Comment

by:jwilcox
ID: 2651159
So if I keep a reference to GroupBox, and to my Combo Boxes, when the dialog returns, I could probably just access them to get which value is set, correct?

Thank you!
0
 
LVL 4

Expert Comment

by:adam923
ID: 2651271
From the Java 2 API:
Show a warning dialog with the options OK, CANCEL, title 'Warning', and message 'Click OK to continue':
     Object[] options = { "OK", "CANCEL" };
     JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
               DEFAULT_OPTION, WARNING_MESSAGE,
               null, options, options[0]);

This showOptionDialog will return an int 0 for OK, 1 for CANCEL
0
Industry Leaders: 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!

 
LVL 1

Author Comment

by:jwilcox
ID: 2651558
Thank you for trying to help adam923, but I'm trying to do a custom dialog, beyond what JOptionPane can do, so I can't use that.

Thank you for the suggestion, however.
0
 
LVL 4

Expert Comment

by:adam923
ID: 2651765
ok, sorry i misunderstood you
0
 
LVL 3

Expert Comment

by:rjackman
ID: 2652564
hi jwilcox
for poping up the JDialog u have to have some event
say for example if i have a button called ShowDialog so when i click the button it should show me the JDialog so what u have to do is register the button for ActionEvent then in method  setJDialog visible

JDialog jd = new JDialog(//what ever params are)
public void actionPerformed(ActionEvent e)
{
  jd.show();
  then if u have text field in jd then u can say

  String s =   jd.jtf.getText();  


}
0
 
LVL 1

Author Comment

by:jwilcox
ID: 2676346
Sorry for taking so long!
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

726 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