Solved

JDialog, OK, and CANCEL

Posted on 2000-03-23
7
1,249 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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

738 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