Solved

JDialog, OK, and CANCEL

Posted on 2000-03-23
7
1,238 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
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…

770 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