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
14
votes
6 answers

How to change background color of JOptionPane?

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…
itro
  • 7,006
  • 27
  • 78
  • 121
14
votes
4 answers

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

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.
Daniel Briskman
  • 399
  • 2
  • 3
  • 11
14
votes
7 answers

How to handle cancel button in JOptionPane

I had created a JOptionPane of type showInputDialog. When it opens it, it shows me two buttons: OK and Cancel. I would like to handle the action when I push on Cancel button, but I don't know how to reach it. How can I get it?
Mazzy
  • 13,354
  • 43
  • 126
  • 207
13
votes
8 answers

Setting component focus in JOptionPane.showOptionDialog()

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},…
ehsun7b
  • 4,796
  • 14
  • 59
  • 98
13
votes
6 answers

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

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…
d1ck50n
  • 1,331
  • 2
  • 16
  • 20
13
votes
4 answers

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

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... ?
Sanziana
  • 189
  • 2
  • 2
  • 4
12
votes
3 answers

Java JOptionPane default text

When I ask a user to enter a quantity for a program I have made using the code below, the default text is 3. String input = JOptionPane.showInputDialog(null, "Please enter new quantity", …
Harry Martland
  • 604
  • 2
  • 14
  • 26
12
votes
3 answers

Remove icon from JOptionPane

How to remove icon from JOptionPane? ImageIcon icon = new ImageIcon(image); JLabel label = new JLabel(icon); int result = JOptionPane.showConfirmDialog((Component) null, label, "ScreenPreview", JOptionPane.OK_CANCEL_OPTION);
Code Hungry
  • 3,930
  • 22
  • 67
  • 95
12
votes
2 answers

Best way to detect whether code is running in an application server java

For a J2EE bean I am reusing code that was developed for a java swing application. JOptionPane.showMessageDialog() is unfortunately commonly used. Most occurences luckily in code sections that are not reused by the J2EE application, but in some…
fredarin
  • 784
  • 5
  • 14
11
votes
2 answers

How to close message dialog programmatically?

I have a question about joptionpane. Using JOptionPane.showMessageDialog(...), we can create a message dialog. But how to close it programmatically?
andrew
  • 885
  • 2
  • 8
  • 16
11
votes
4 answers

JOptionPane and scroll function

I want to JList a lot of results in a JOptionPane, however, I'm not sure how to add in a scroll function should there be too many results. How would I add a scroll bar to a JOptionPane? Any help would be great. Thanks.
user1060187
  • 957
  • 5
  • 12
  • 28
11
votes
5 answers

How to change Yes/No option in confirmation dialog?

I want to change YES and NO to something like Agree/Disagree. What should I do? int reply = JOptionPane.showConfirmDialog(null, "Are you want to continue the process?", …
Kashama Shinn
  • 241
  • 2
  • 4
  • 11
10
votes
4 answers

To break a message in two or more lines in JOptionPane

try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String connectionUrl = "jdbc:sqlserver://"+hostName.getText()+";" + …
Raj Gupta
  • 260
  • 3
  • 6
  • 18
10
votes
2 answers

"Un-rollover" a JButton when a JOptionPane is displayed

I have a situation where I need to display a JOptionPane after clicking on a JButton. The JButton has a default icon, and a rollover icon (which displays when, well, the mouse rolls-over the button). However, once the button is clicked and a…
aspiring_sarge
  • 2,355
  • 1
  • 25
  • 32
10
votes
3 answers

JOptionPane with username and password input

I have my own Dialog pop up with two textfields, two JLabel and a "ok" JButton. The pop up is a login window. The window works perfect I just want to know how I am able to add a "cancel" JButton, so the user is able to cancel the login. Here is my…
Gerret
  • 2,948
  • 4
  • 18
  • 28