?
Solved

JDialog, OK, and CANCEL

Posted on 2000-03-23
7
Medium Priority
?
1,261 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 240 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

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