joptionpane

Closing JOptionPane.ShowInternalOptionDialog programmatically

柔情痞子 提交于 2019-12-11 00:15:43
问题 My current design is like this: I have an outer frame that displays main app. When user clicks a button on the main app, a pop-up Window should be launched. I am using JOptionPane.showInternalOptionDialog and passing button objects as options. When user clicks one of these button, it should run certain commands and then close the window. I was not able to close the Frame that shows the pop-up. I found a similar question in this forum, that suggests the following workaround. Closing a dialog

JOptionPane equivalent in C#?

廉价感情. 提交于 2019-12-10 22:26:16
问题 In Java there's a useful class in the standard Swing libraries called 'JOptionPane' that provides a bunch of pre-made but customizable windows for displaying messages and getting (simple) user input. I know there's 'MessageBox.Show(..)' to display Yes/No/Cancel type messages to the user in C#, but is there an equivalent class (or simple library) that provides easy-to-use customizable input boxes? Something like the functionality available from JOptionPane is what I'm looking for. 回答1: As of

Java JOptionPane.showConfirmDialog hot key

冷暖自知 提交于 2019-12-10 17:25:29
问题 I am displaying a confirmation dialog in Java using JOptionPane.showConfirmDialog. The dialog shows a Yes No confirmation to the user. This is called as follows: int result = JOptionPane.showConfirmDialog(sessionObjects.getActiveComponent(), "Are you sure you want to exit?", "My App", JOptionPane.YES_NO_OPTION); The question is as this is a simple confirmation, can the user press y for yes and n for no? At present the user has to click on the buttons? Thanks, Andez 回答1: You already have

How to make a “do not ask me again” dialog pop-up box with java?

人盡茶涼 提交于 2019-12-10 13:09:48
问题 In one part of my program I use a JOptionPane to ask the user if they are sure of what he will do. But I do not want to bore the user asking that every time you try so I like to use the function of some dialog boxes in android that come with the "Do not ask again", but do not know how to implement that in my program, someone here you could help me? (Should have a Spanish StackOverflow) This is my code if (jCheckBox2.isSelected() && jCheckBox1.isSelected()){ JOptionPane.showConfirmDialog(null,

how to change the default text of buttons in JOptionPane.showInputDialog

*爱你&永不变心* 提交于 2019-12-10 12:37:27
问题 I want to set the text of OK and CANCEL buttons in JOptionPane.showInputDialog to my own strings. There is a way to change the buttons' text in JOptionPane.showOptionDialog , but I couldn't find a way to change it in showInputDialog . 回答1: If you want the JOptionPane.showInputDialog with custom button texts, you could extend JOptionPane: public class JEnhancedOptionPane extends JOptionPane { public static String showInputDialog(final Object message, final Object[] options) throws

JOptionPane.YES_OPTION == ENTER on each button

若如初见. 提交于 2019-12-10 09:21:55
问题 I have a option dialog like this: String[] options = ["Yes", "No"]; //button names int n = JOptionPane.showOptionDialog(singleFrameService.getFrame(), "Some Question?", "", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, //do not use a custom Icon options, //the titles of buttons options[0]); //default button title //if press yes if (n == JOptionPane.YES_OPTION){ //make some if pressed Yes } When I used mouse and press Yes/No - all work fine... But when I start use keyboard,

Why does JOptionPane.getValue() continue to return uninitializedValue

孤街醉人 提交于 2019-12-08 10:45:15
问题 Below are my code public static void main(String args[]){ JOptionPane pane = new JOptionPane(); pane.showInputDialog(null, "Question"); Object value = value.getValue(); System.out.println(value.toString()); --> this will print out uninitializedValue } I basically want to detect when the user click the cancel in JOptionPane and when the user close the JOptionPane 回答1: You should do this: String s = JOptionPane.showInputDialog(null, "Question"); System.out.println(s); This will return a null

How to wait for JOptionPane to be closed before dispatching any more events

白昼怎懂夜的黑 提交于 2019-12-08 07:16:32
问题 I have a couple text fields that I'm tabbing between. On focusLost() I am opening a JOptionPane . I would like the code in focusGained() to be executed AFTER the JOptionPane has been closed. Even though the dialog is modal, focusGained() is being called before the JOptionPane is closed. Is there any way around this? Found this similar question, but it doesn't seem to have been solved either. Postpone Event Queue after Focus Lost Here's a code sample. You'll notice "Focus Gained" is printed

How to validate if Text entered is a numeric number?

倾然丶 夕夏残阳落幕 提交于 2019-12-07 20:58:43
问题 I have a calculation application which I need to validate the fields to check if the values entered are numeric numbers and not alphanumeric. I have some ideas about the codes. Please guide me if I have done anything wrong or seem noob as this is my first time trying out Swing. private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) { String text1 = jTextField1.getText(); // TODO add your handling code here: } private void jTextField2ActionPerformed(java.awt.event.ActionEvent

JOptionPane showOptionDialog

て烟熏妆下的殇ゞ 提交于 2019-12-07 10:58:46
问题 I want to create a showOptionDialog using JOptionPane that has two buttons: Metric and Imperial. If say, Metric is clicked on, the Metric GUI will load. Conversely, if Imperial is clicked on, then the Imperial GUI will load. How do I do this? Many thanks. 回答1: int choice = JOptionPane.showOptionDialog(null, //Component parentComponent "Metric or Imperial?", //Object message, "Choose an option", //String title JOptionPane.YES_NO_OPTION, //int optionType JOptionPane.INFORMATION_MESSAGE, //int