Solved

JDialog, OK, and CANCEL

Posted on 2000-03-23
7
1,227 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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 …

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now