joptionpane

Java - How to add a JOptionPane for Yes and No options

放肆的年华 提交于 2019-11-28 13:58:38
So, I've read the Java API, but still can't seem to make heads or tails about how to do this. And believe me I have tried. I want an ActionListener to cause a message box with the text 'Do you really want to exit?', with options yes and no which exits the program or not depending on the selected button. Here's what I have for the ActionListener before I started to break it with the message box: exitItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { window.dispose(); } } ); How can I suitably change it to meet my requirements? I think you want to do

ActionListener on JOptionPane

自闭症网瘾萝莉.ら 提交于 2019-11-28 13:53:47
I am following the Oracle tutorial on how to create a custom dialog box: http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html I have two buttons: Save Object and Delete Object which when clicked should execute a certain piece of code. Unfortunately I can't seem to add any ActionListener to the JOptionPane buttons so when they're clicked nothing happens. Can anyone help tell me how I can go about doing this? Here is the class I have for the dialog box so far: class InputDialogBox extends JDialog implements ActionListener, PropertyChangeListener { private String typedText = null

JOptionPane not displaying correctly?

安稳与你 提交于 2019-11-28 12:34:44
Today I updated my jdk and docs from 7 to 8. I made a few changes to my program, and now when I try to have the program use JOptionPane, JLabel, ..., everything messes up. I made a separate tester class whose sole purpose is to run a single JOptionPane box and the error still occurred. Below is a picture of what the dialog box looks like. Is there something seriously wrong with Java 8? import javax.swing.JOptionPane; public class CirclePointTester { public static void main(String [] args) { String input = JOptionPane.showInputDialog("Enter the x coordinate of the circle"); int xc = Integer

How to make JOptionPane.showConfirmDialog have No selected by default?

允我心安 提交于 2019-11-28 11:53:47
I implemented a Save As dialog in Java that prompts the user if the file already exists, and I want the No option to be selected by default. How do I do this? Here is my current code: JFileChooser chooser = new JFileChooser() { public void approveSelection() { File selectedFile = getSelectedFile(); if (selectedFile != null && selectedFile.exists( ) ) { int response = JOptionPane.showConfirmDialog( this, "The file " + selectedFile.getName() + " already exists." + " Do you want to replace the existing file?", getDialogTitle(), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (response

GUI in java “go to previous/next” option?

随声附和 提交于 2019-11-28 11:01:34
问题 Is there a way to have an option to go the a previous message dialog box or a next one? I have a program where after all the input and math calculations is done, a message dialog box appears with the information for "Person 1" then you press ok and the one for "Person 2" appears. It would be nice if there could be an option to be able to navigate between the different dialog boxes. Here is the part of the program that prints the messages. for (i = 0; i < NumEmployees; i++) { JOptionPane

JOptionPane won't show its dialog on top of other windows

社会主义新天地 提交于 2019-11-28 11:01:28
I have problem currently for my swing reminder application, which able to minimize to tray on close. My problem here is, I need JOptionPane dialog to pop up on time according to what I set, but problem here is, when I minimize it, the dialog will pop up, but not in the top of windows when other application like explorer, firefox is running, anyone know how to pop up the dialog box on top of windows no matter what application is running? Walter Create an empty respectively dummy JFrame, set it always on top and use it as the component for the JOptionPane instead of null. So the JOptionPane

switching JPanel within main window

半城伤御伤魂 提交于 2019-11-28 09:58:04
问题 I have an application that allows users to select an option and based on the user selection a JPanel is removed from the Component, the new JPanel is added and the component is revalidated see code: if (c != null) { contentPane.remove(c); } c = new AddBookInterface(theLibrary); contentPane.add(c); contentPane.revalidate(); break; c is a Component I have several JPanels that the user can switch between and the switch works properly. However, when I add this JPanel upon user selection the

How to change background color of JOptionPane?

不想你离开。 提交于 2019-11-28 08:31:42
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) { }` By using the UIManager class import javax.swing.UIManager; UIManager UI=new UIManager(); UI.put("OptionPane.background",new ColorUIResource(255,0,0)); UI.put("Panel.background",new ColorUIResource(255,0,0)); or UIManager UI=new UIManager(); UI.put("OptionPane

How do I Prompt the user to enter a password before entering the main program?

拥有回忆 提交于 2019-11-28 08:22:43
问题 What I need to do is to prompt the user with a username and password (authentication is done locally) and if it checks out, the user would then be able to access the main program body. public static void main(String[] args){ //String input = JOptionPane.showInputDialog("Enter password to continue: "); //input2 = Integer.parseInt(input); // followed by the creation of the main frame new Cashier3(); Cashier3 frame = new Cashier3(); frame.setTitle("CASHIER 2"); frame.setDefaultCloseOperation

How can I set the location of a JOptionPane?

半腔热情 提交于 2019-11-28 06:36:30
问题 I have a splash window that pops up while the program loads. This splash window uses the method setAlwaysOnTop(true) , which is something I would prefer to keep. The issue comes when a separate part of the program pops up a JOptionPane to notify the user they need to update the software. On Linux this appears in front of the Splash window, but on Windows it appears behind, barely visible to the user who then might sit for 30mins - hour before finding out why it's not loaded yet. A fix I'd