Questions tagged [joptionpane]

JOptionPane is a Java class that makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something.

JOptionPane makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something. For information about using JOptionPane, see How to Make Dialogs, a section in The Java Tutorial. Related examples may be found here.

1895 questions
9
votes
3 answers

Clicking the cancel button showInputDialogue

I have a question in regards to pressing the cancel button of my inputDialoguebox. I have asked a similar question before so I apologize if I seem to repeat myself. The main problem I have is that my code executes regardless of me pressing cancel…
Arianule
  • 8,811
  • 45
  • 116
  • 174
9
votes
4 answers

When I try to use HTML with `JOptionPane`, HTML tags are printed instead of HTML formatting

For some weird reason when I try to use HTML with JOptionPane, HTML tags are printed instead of HTML formatting. String msg = "Please fix this"; JLabel message = new…
jadrijan
  • 1,438
  • 4
  • 31
  • 48
9
votes
4 answers

How do you change the size and font of a joptionpane?

Can you change the font and size of the text of a JOptionPane? I tried it and it works only if I "run file" on that specific java class. If you start the whole project it does not change the font. I only want to change only a specific JOptionPane…
nonickname
  • 181
  • 1
  • 3
  • 10
9
votes
2 answers

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

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…
bioMind
  • 171
  • 1
  • 2
  • 9
9
votes
2 answers

Making a JOptionPane with 4 options

I need to make a custom dialog with 4 options but as far as I can tell you can only have one with three options. Here is how I would make an option pane with 3 options: Frame refFrame = DialogUtils.getReferenceFrame(); ///TODO: …
Mike2012
  • 7,629
  • 15
  • 84
  • 135
9
votes
3 answers

Customize JOptionPane Dialog

I am learning java swing. The code below is a catch block which handles an IOException and shows a error message. catch(IOException e) { System.out.println("IOException"); JOptionPane.showMessageDialog(null,"File not…
Victor Mukherjee
  • 10,487
  • 16
  • 54
  • 97
9
votes
4 answers

Get the return value of JOptionPane

My JOptionPane code is as follows: selectedSiteName = JOptionPane.showInputDialog("Enter the name of the new site:"); This renders out an input with a textbox and an OK and Cancel button. I need to detect if Cancel was clicked. Cheers.
burntsugar
  • 57,360
  • 21
  • 58
  • 81
8
votes
2 answers

JOptionPane showInputDialog position

How can I specify the position of a JOptionPane. Can anyone make a class that extends JOptionPane.showInputDialog that also takes in an x,y position?
CodeGuy
  • 28,427
  • 76
  • 200
  • 317
8
votes
3 answers

Change the OK Cancel string in JOptionPane

I was wondering is it possible to change the OK Cancel Button to custom string in java? I have JOptionPane.showConfirmDialog(message, title, JOptionPane.OK_CANCEL_OPTION); Right now, the button will show "OK" and "Cancel". Is it possible to change…
Harts
  • 4,023
  • 9
  • 54
  • 93
8
votes
2 answers

java.util.IllegalFormatConversionException: f != java.lang.String Error

import javax.swing.JOptionPane; public class Minutes { public static void main(String[] args) { double BasePlanCost = 20; final double BaseCostPerMinute=0.15; double MinutesUsed =…
Jeff
  • 85
  • 1
  • 1
  • 6
8
votes
6 answers

JOptionPane Input to int

I am trying to make a JOptionPane get an input and assign it to an int but I am getting some problems with the variable types. I am trying something like this: Int ans = (Integer) JOptionPane.showInputDialog(frame, "Text", …
kxk
  • 576
  • 2
  • 11
  • 30
8
votes
2 answers

Resize dialog message (JOptionPane) for long sentence with fixed width

I'm trying to resize the height of the dialog box (JOptionPane) for long sentence with hyperlink. My code is .. public class DialogTest { public static void main(String[] args) throws Exception { JTextPane jtp = new JTextPane(); Document doc…
swordartist
  • 302
  • 2
  • 3
  • 8
8
votes
2 answers

Closing A JOptionPane Programmatically

I am working on a project in which I would like to close a generic JOptionPane programmatically (by not physically clicking on any buttons). When a timer expires, I would like to close any possible JOptionPane that may be open and kick the user back…
Codester89
  • 93
  • 1
  • 2
  • 5
8
votes
3 answers

Update a JOptionPane to reflect a component state change

Have a method in my GUI project for displaying a JOptionPane with several components on it. Two of these components are ButtonGroups with two JRadioButtons in each, in the first group the first button is selected by default, and in the second group…
8
votes
3 answers

Enable text highlighting in swing message-box

Say i'm using the following code to prompt an error message in my simple swing application: JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE); Is there any way I could make it possible for the user to highlight text…
sgrossman
  • 105
  • 2
  • 7