joptionpane

Setting component focus in JOptionPane.showOptionDialog()

独自空忆成欢 提交于 2019-11-27 03:55:49
问题 In order to have custom button captions in an input dialog, I created the following code: String key = null; JTextField txtKey = new JTextField(); int answerKey = JOptionPane.showOptionDialog(this, new Object[] {pleaseEnterTheKey, txtKey}, decryptionKey, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] {okCaption, cancelCaption}, okCaption); if (answerKey == JOptionPane.OK_OPTION && txtKey.getText() != null) { key = txtKey.getText(); } How can I move the focus

Java - How to create a custom dialog box?

◇◆丶佛笑我妖孽 提交于 2019-11-27 03:53:38
I have a button on a JFrame that when clicked I want a dialog box to popup with multiple text areas for user input. I have been looking all around to try to figure out how to do this but I keep on getting more confused. Can anyone help? If you don't need much in the way of custom behavior, JOptionPane is a good time saver. It takes care of the placement and localization of OK / Cancel options, and is a quick-and-dirty way to show a custom dialog without needing to define your own classes. Most of the time the "message" parameter in JOptionPane is a String, but you can pass in a JComponent or

How to change background color of JOptionPane?

大城市里の小女人 提交于 2019-11-27 02:17:36
问题 I have added JOptionPane to my application but I do not know how to change background color to white? `int option = JOptionPane.showConfirmDialog(bcfiDownloadPanel, new Object[]{"Host: " + source, panel}, "Authorization Required", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE ); if (option == JOptionPane.OK_OPTION) { }` 回答1: By using the UIManager class import javax.swing.UIManager; UIManager UI=new UIManager(); UI.put("OptionPane.background",new ColorUIResource(255,0,0)); UI.put(

How to present a simple alert message in java?

走远了吗. 提交于 2019-11-26 23:57:27
问题 Coming from .NET i am so used calling Alert() in desktop apps. However in this java desktop app, I just want to alert a message saying "thank you for using java" I have to go through this much suffering: (using a JOptionPane) Is there an easier way? 回答1: I'll be the first to admit Java can be very verbose, but I don't think this is unreasonable: JOptionPane.showMessageDialog(null, "My Goodness, this is so concise"); If you statically import javax.swing.JOptionPane.showMessageDialog this

Closing a runnable JOptionPane

十年热恋 提交于 2019-11-26 23:06:29
I have this Runnable window: EventQueue.invokeLater(new Runnable(){ @Override public void run() { op = new JOptionPane("Breaktime",JOptionPane.WARNING_MESSAGE); dialog = op.createDialog("Break"); dialog.setAlwaysOnTop(true); dialog.setModal(true); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); } }); Is it possible that I can have a timer here to close this within 1 or 2 minutes instead of clicking the OK button? Yes, the trick would be to get the Timer started before you call setVisible ... public class AutoClose02 { public static void main(String[] args) {

JOptionPane - check user input and prevent from closing until conditions are met

白昼怎懂夜的黑 提交于 2019-11-26 22:35:47
Please can someone tell me if there is a convenient way of prevent JOptionPane from closing upon clicking OK unless the conditions for user input fields are met? Or do I have no choice but to use JFrame ? My validation logic so far. Doesn't seem to work because the buttons are one-time clickable to some reason... final JDialog dialog3 = new JDialog(OmniGUI.getFrame(), "Create new Node - id:" + newNodeID); dialog3.setContentPane(theOPane); dialog3.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); theOPane.addPropertyChangeListener(new PropertyChangeListener(){ public void propertyChange

Why does setSelected on JCheckBox lose effect?

偶尔善良 提交于 2019-11-26 21:03:49
Can someone explain to me why I lost the selection (set by setSelected() ) for JCheckBox when I put the JOptionPane into the ItemListener ? Is this a bug ? It is curious, that if this process is delayed with invokeLater() , setSelected() works correctly as I expected. from SSCCE import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ComponentEventDemo extends JPanel implements ComponentListener, ItemListener { private static final long serialVersionUID = 1L; private JFrame frame; private JTextArea display; private String newline = "\n"; private JTextField field1; public

Timer or other idea required to allow code to continue execution after calling method and JOptionPane

廉价感情. 提交于 2019-11-26 18:35:59
问题 I need a way to allow my program to keep running code after this method is called. Currently, it waits for half an hour, gets the info, stores it to the object WeatherCard, and displays it, and repeats. But it hangs on the JOptionPane. I need a way to make it so that the program either keeps going underneath the JOptionPane or to close the pane after about 10 seconds. I am not sure how to work either into my code, currently public void printWeatherCard(WeatherCard w, JFrame controlFrame)

trouble obtaining variable info from another JFrame

北战南征 提交于 2019-11-26 18:35:29
问题 I am trying to create something similar to a JOptionPane but will obtain more than one(3) variables from input. So I figured I would use a separate JFrame that had three textFields. I used access methods like Get and Set to get the variables from one class to another, but I am getting a null pointer excpetion. I figure I am going about getting the variables the wrong way, and am having a hard time trying to find a viable solution. public class Instructor() { public void Insert(JPanel panel) {

Disable ok button on JOptionPane.dialog until user gives an input

旧巷老猫 提交于 2019-11-26 17:50:32
问题 I need the user to input a name and I want to disable the ok button until some input is given. How can I disable it... ? 回答1: JOptionPane allows you to supply a component as the message pane and the controls/options that can be displayed on it. If you add the correct listeners to the message component, then you should be able to influence the controls that are used as options. Take a look at JOptionPane.showOptionDialog(Component parentComponent, Object message, String title, int optionType,