joptionpane

Custom dialog using JOptionPane API won't dispose

≡放荡痞女 提交于 2019-12-22 09:52:05
问题 I've been just playing with JOptionPane API to show a custom dialog and I've found a strange situation: when I choose either OK or Cancel option or press Esc key this dialog won't dispose as expected. The thing is, instead of using this single line to display a modal dialog: JOptionPane.showConfirmDialog( null , "The quick brown fox jumps over the lazy dog." , "New Dialog" , JOptionPane.OK_CANCEL_OPTION , JOptionPane.PLAIN_MESSAGE); I wanted to use the API, setting all the parameters one by

JoptionPane ShowConfirmDialog

妖精的绣舞 提交于 2019-12-22 09:35:57
问题 I have a Java program. When I run the program, it will give me a GUI which as I attached. When I want to close it, it will prompt out a confirm dialog. If I press the Yes button, it will quit the program using System.exit() . public static void main(String args[]) { ButtonTest app = new ButtonTest( ); app.addWindowListener( new WindowAdapter( ) { public void windowClosing (WindowEvent e) { String message = " Really Quit ? "; String title = "Quit"; int reply = JOptionPane.showConfirmDialog

Setting Mnemonics and Hot Keys for a JOptionPane Dialog

吃可爱长大的小学妹 提交于 2019-12-22 08:59:55
问题 Is it possible to assign hotkeys and mnemonics to the buttons in a JOptionPane Dialog? I'd like to be able, in a JOptionPane generated message dialog with the options Yes, No and Cancel, press Y to hit the Yes button, N to hit the No button and escape to activate the escape button. Similarly in a dialog with Okay and Cancel buttons I'd like to be able to activate them with enter and escape. I've attempted passing JButtons into the JOptionPane's button Object array with the Mnemonics set

Custom Cursor in a Swing JDialog

丶灬走出姿态 提交于 2019-12-22 08:26:31
问题 I have a Java Swing application, developed on Mac OS X 10.5 using Java 1.5. I'm trying to make a custom cursor appear when the user moves the mouse over some text in a dialog. The cursor never changes, though. When I don't use a JFrame instead of a JDialog, the cursor does change. But then I'll have to write all the dialog code myself. How can I get the cursor to appear? Here's the simplest code I could create to demonstrate the problem: import javax.swing.*; import java.awt.*; public class

How can I add a listener on the ok button of JOptionPane? [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-12-22 05:18:30
问题 This question already has answers here : Java Dialog - Find out if OK is clicked? (4 answers) Closed 3 years ago . How can I add a listener on the click of "OK" button of JOptionPane.INFORMATION_MESSAGE . My JOptionPane is: JOptionPane.showMessageDialog(null, "Your password is: " + password, "Your Password", JOptionPane.INFORMATION_MESSAGE); 回答1: The showMessageDialog method returns void when the user closes or clicks ok. But you can use the method JOptionPane.showOptionDialog with a single

“Un-rollover” a JButton when a JOptionPane is displayed

十年热恋 提交于 2019-12-22 04:06:10
问题 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 JOptionPane appears, the rollover icon does not change back to the original, and continues to remain so until the user brings the mouse back to the JButton's frame after selecting an appropriate JOptionPane choice. How would I "un-rollover" the JButton

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

醉酒当歌 提交于 2019-12-21 15:47:06
问题 For some weird reason when I try to use HTML with JOptionPane , HTML tags are printed instead of HTML formatting. String msg = "Please fix <HTML><BODY BGCOLOR=#FFCCCC>this</BODY></HTML>"; JLabel message = new JLabel(msg); JOptionPane.showMessageDialog(MyApp.this, message, "Error!", JOptionPane.ERROR_MESSAGE); and the output is: Please fix <HTML><BODY BGCOLOR=#FFCCCC>this</BODY></HTML> 回答1: The entire string needs to be enclosed within the HTML tags. For example: button = new JButton("<html><b

JOptionPane YES NO OPTION [duplicate]

笑着哭i 提交于 2019-12-21 05:38:11
问题 This question already has answers here : JOptionPane Yes or No window (8 answers) Closed 3 years ago . I got an JOptionPane and yes and no buttons. But, whichever button you click it still exists. HELP! Heres the code: int dialogButton = JOptionPane.YES_NO_OPTION; JOptionPane.showConfirmDialog (null, "Are you sure?","WARNING", dialogButton); if(dialogButton == JOptionPane.YES_OPTION) { System.exit(0); if(dialogButton == JOptionPane.NO_OPTION) { remove(dialogButton); } } 回答1: You should

Java: Custom Buttons in showInputDialog

*爱你&永不变心* 提交于 2019-12-21 03:42:08
问题 How do you add custom text to the buttons of a JOptionPane.showInputDialog? I know about this question JOptionPane showInputDialog with custom buttons, but it doesn't answer the question asked, it just references them to JavaDocs, which doesn't answer it. Code So Far: Object[] options1 = {"Try This Number", "Choose A Random Number", "Quit"}; JOptionPane.showOptionDialog(null, "Enter a number between 0 and 10000", "Enter a Number", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,

How do I show only the first letters of a string?

馋奶兔 提交于 2019-12-20 08:15:11
问题 I'm prompting the user to enter their first and last name but I can't figure out how to show just their first and last initials import javax.swing.*; //import java.awt.*; public class Lab2Program2 { public static void main (String [] args) { String firstName; String lastName; firstName = JOptionPane.showInputDialog(null, "What is your first name?"); lastName = JOptionPane.showInputDialog(null, "What is your last name?"); JOptionPane.showMessageDialog(null, " Your initials are " + firstName +