JOptionPane 2 « JOptionPane « Java Swing Q&A





1. NullPointerException thrown in JOptionPane    coderanch.com

I don't understand why this happens in this code. The only difference I see is that the first two numbers are doubles and the third is an int, but the exception is caught for the first two and not the third. The third throws the NumberFormatException. But if I hit Cancel BEFORE parseInt() is called, why am I getting a NumberFormatException? ...

2. JOptionPane and ArraySize not known    coderanch.com

If I was to use JOptionPane to get user input, with the opportunity to type exit when the user has finished entering their data, And I wanted to store the data they had input in an array would I have to use a dynamic array? (As I would need the array to grow in size to accommodate the number of user ...

3. JOptionPane    coderanch.com

When using JOptionPane to get input from a user and you wish to write code to do something i.e. Println ("Program finished") when the user selects the Cancel button. What would you write? Would you write: dataInput = JOptionPane.showInputDialog(message1); OK = dataInput.equals(null); if (OK) { System.out.println("Cancel has been selected. Data Input finished."); }//end if statement When I did this I got ...

4. trouble importing javax.swing.JOptionPane    coderanch.com

Are you using an older version of Java. I believe Swing is added to the standard classes since 1.3. If you are using an older version you can add the swing classes to the classpath (I don't know what the jar was called but it exists.) Maybe it is a better idea to use a newer JDK anyway, especially if you ...

5. help with JOptionpane    coderanch.com

May as well warn you now, your name doesn't fit the naming policy. In other words you need to have a full last name, not an inital! And on your code, the whole putting an int to an optionPane just doesn't seem right to me, but I'm not very experenced and it may be perfectly fine. Sorry I'm not of much ...

6. Help with JOptionPane    coderanch.com

7. app doesn't exit because of JOptionPane    coderanch.com

Hi all, I'm reading head first java and tried writing the guess-the-number game myself. It's just a simple game, and it works until I use JOptionPane for a parameter, instead of hard-coding it myself. To decide how many players are guessing numbers, I can use one of these: g.startGame(Integer.parseInt(JOptionPane.showInputDialog("How many players?"))); OR: g.startGame(4); The second solution works fine, the first makes ...

8. JOptionPane problems    coderanch.com

9. JOptionPane - Browser    coderanch.com





10. JOptionPane    coderanch.com

11. Problem with keystrokes and JOptionPane    coderanch.com

Thanks for the reply here is the sample code import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.KeyStroke; /** * * @author Administrator */ public class TestFrame extends javax.swing.JFrame { private ActionListener listener; /** Creates new form TestFrame */ public TestFrame() { initComponents(); } /** This method is called from within the constructor to * initialize the form. ...

12. Pressing in JOptionPane    coderanch.com

13. JOption Pane problem    coderanch.com

Hello All, I am trying to get the following code to compile and run, I am getting an error message: Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Number at java.text.DecimalFormat.format(Unknown Source) at java.text.Format.format(Unknown Source) at Converter.main(Converter.java:55) Here is the code: import java.awt.Component; import javax.swing.JOptionPane; import java.text.DecimalFormat; public class Converter { private static Component frame; /** Creates a ...

14. How to increase the size of JOptionPane    coderanch.com

If you look at the source code for JOptionPane, you will notice that a pack() is called on the dialog. This is for a very good reason. Dialogs should be used to to convey minimal but important information to the users. Considering this, the dialog size is kept at a minimum and that is the reason why you were not able ...

15. Java Swing JOptionPane Question ?    coderanch.com

Hey I have written a Code to get an user input through JOptionPane.showInputDialog() And It has two buttons called "ok" and " cancel". How Can i replace those strings "ok" and "cancel" with my own names??How to do that? And another thing is How to pop up a confirmation dialog box when i press close button on JOptionPane.showInputDialog box.Tell me a ...

16. simple JOptionPane help    coderanch.com

I've created a dialog box with the options YES/NO but I now I want to perform another task depending on which button the users clicked. I think I need an if statement saying: if yes is clicked then delete row, if no is clicked, do nothing. I'm unsure what to put in the brackets of my if statement. I know how ...





17. err get and set methods and scanner class / JOptionPane    coderanch.com

thanks for your reply ryan yes i did that part but im not sure what to put for the get method i pasted my code here public class Customer{ private String name; private String icNo; public void setName(String n){ n=name; } public void setName(String i){ i=icNo; } } import java.util.Scanner; public class topmethod{ public static void main(String args[]){ Customer d = ...

18. cant find method from JOptionPane class    coderanch.com

I am trying to compare the input from a JOptionPane to string literal and execute an event based on if the values match or not. I do understand that .equalsIgnoreCase() is not part of the JOptionPane class, but I dont know any other way to compare string values. here are my errors: C:\Documents and Settings\ben\Desktop\park>javac BenHultinProg7.java .\Prog7.java:90: cannot find symbol symbol ...

19. JOptionPane with Multiple InputText boxes    coderanch.com

JPanel panel = new JPanel(); JTextField field1 = new JTextField(10); panel.add(field1); JTextField field2 = new JTextField(10); panel.add(field2); JTextField field3 = new JTextField(10); panel.add(field3); int value = JOptionPane.showConfirmDialog(frame, panel, "Enter text", JOptionPane.OK_CANCEL_OPTION); if (value == JOptionPane.OK_OPTION) { // OK was pressed String s1 = field1.getText(); String s2 = field2.getText(); String s3 = field3.getText(); // handle them }

20. Blank JOptionPane RMI    coderanch.com

I am creating an RMI project but I am running into a problem when I go to display JOptionPanes. When updating the Clients from the server, my game is supposed to display a message to every player if someone won the game but the JOptionPane just shows a blank box with a title, no message or button. I can't figure out ...

21. change language JOptionPane    coderanch.com

22. Question about JOptionPane    coderanch.com

24. JOptionPane not working    coderanch.com

public class ClientView extends FrameView { private Control ctrl; public ClientView(SingleFrameApplication app) { super(app); initComponents(); ctrl = new Control(this); ctrl.start(); } private void login(java.awt.event.MouseEvent evt) { logMeIn(); } private void press(java.awt.event.KeyEvent evt) { this.log.setEnabled(true); } private void logMeIn(){ char[] arr = pword.getPassword(); String pass = ""; for(char a: arr){ pass = pass + a; } ctrl.login(uName.getText(), pass); } private void notice(){ ...

25. JOptionPane Question!    coderanch.com

26. JoptionPane issues    coderanch.com

My issue is that i need to Write a class that accepts a user's hourly rate of pay and the numb er of hours worked. display the user's Gross pay, the witholding tax(15% of gross pay), and the net pay (grosspay - Withholding) i have no idea where to start i am completely lost

27. JOptionPane issue    coderanch.com

public void selfIntersection() { NLanguage title = Enum.valueOf(NLanguage.class, "GC_IntersectTitle"); NLanguage intersect = Enum.valueOf(NLanguage.class, "GC_Intersection"); JOptionPane.showMessageDialog(this, intersect.getText(), title.getText(), JOptionPane.WARNING_MESSAGE); try { SwingUtilities.invokeLater(new Runnable() { public void run() { requestFocus(); } }); } catch (InterruptedException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } ; try { Robot robot = new Robot(); Point2D lastPoint = m_objNDrawPanel.getPoints().lastElement(); lastPoint = m_graphicPanel.transformWorldToView(lastPoint); Point2D screenLocation = ...

28. quick choises in JoptionPane    java-forums.org

The short answer, as far as I know, is "no". Some Swing components are very good about allowing you to type the first letter of the option, and the list will shift to that point. I believe JComboBox does that, which is part of JOptionPane. Also, JTree allows you to type several letters, and it will continue positioning the list to ...

29. problems with JOptionPane    java-forums.org

30. Unable To Stop JOptionPane Warning In A While Statement    java-forums.org

Unable To Stop JOptionPane Warning In A While Statement I have tried everything I know to create a else inside of a while loop to take a false return value and put out a warning message pops up, lets you click ok, resets focus, clears field and allows for the correct entry to be made. I have included the ...

31. JOptionPane    java-forums.org

I'm trying to get three different inputs from the user in one JOptionPane.showInputDialog. I figured out how to use the JOptionPane.showMessageDialog to print any number of outputs, I don't need the whole code just the few lines that will allow me to get three inputs from the users. I need to do calculations on them too. Thank you

32. Modify JOptionPane    java-forums.org

33. JOptionPane stopping timer    java-forums.org

You mean this? Java Code: JOptionPane pane = new JOptionPane(arguments); pane.set.Xxxx(...); // Configure JDialog dialog = pane.createDialog(parentComponent, title); dialog.show(); Object selectedValue = pane.getValue(); if(selectedValue == null) return CLOSED_OPTION; //If there is not an array of option buttons: if(options == null) { if(selectedValue instanceof Integer) return ((Integer)selectedValue).intValue(); return CLOSED_OPTION; } //If there is an array of option buttons: for(int counter = 0, ...

34. JOptionPane    java-forums.org

JOptionPane I'm working on the game of life and everything is basically done but the option pane. I need the optionpane to state when the cells stop shifting to state that a steady state has been reached. I have the area I used for this commented out. If some one can help me with this I'll really appreciate it. ...

35. Problem JOptionPane try catch    java-forums.org

import javax.swing.JOptionPane; public class trycatch { public static void main(String args[]) { boolean loop=false; do { try { String strinput=JOptionPane.showInputDialog(null,"Enter a integer"); int input=Integer.parseInt(strinput); } catch(NumberFormatException ex) { OptionPane.showMessageDialog(null,"Invalid value entered"); loop=true; } }while(loop); } } can some one help me solve this , the problem is once the exception is catch then the CANCEL & CLOSED OPTION cant close the ...

36. JOptionPane Troubles    java-forums.org

37. Help with JOptionPane    java-forums.org

I think you've misunderstand my comment. I'm talking about the logical meaning of that. As your examples in first line of code, deals with strings, you define them as it is. In the second line it's just and an addition of integer values, and the last on is just mixing them. Same thing I'm pointed, may be the explanation not clear ...

38. JOptionPane notification    java-forums.org

If an application is minimized, is there a way to notify the user that a JOptionPane has popped up? The program is like a flash card application and I use JOptionPane.showMessageDialog(...) to show the right answer. However it can be set for any time length so it may be minimized for a long time. If this happens, there is no notification ...

39. need help for JOptionPane....    java-forums.org

hi. I'm noe struggling with using JOptionPane. The question which I was assigned to do this. You are to write a program that will accept a positive integer in the range 0 to 9999, i.e. the integer has a maximum of 4 digits.s input and then outputs the digits one per line. The input/output must be via dialog boxes. The following ...

40. JOptionPane when called from inside the paintComponent() method    java-forums.org

import javax.swing.*; import java.awt.Graphics; public class JPanel01 extends JPanel { @Override public void paintComponent(Graphics g) { super.paintComponent(g); testD(); } void testD() { javax.swing.JOptionPane.showMessageDialog(null, "Syntax Error : ", "Incorrect user input", javax.swing.JOptionPane.ERROR_MESSAGE); } public static void main(String args[]) { javax.swing.JFrame frame = new javax.swing.JFrame("Two-Dimensional Graph Sketcher"); frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); frame.add(new JPanel01()); frame.setSize(1280, 770); frame.setVisible(true); } }

41. Help with JOptionPane    java-forums.org

42. JOptionPane    java-forums.org

44. My JOptionPane Scrolls to Bottom!    java-forums.org

Hi. I have a JOptionPane which includes a JTextArea. I did this as I wanted to be able to control the size of the JOptionPane and have a scrolling feature. However, the problem is if the string which is imported into the text area is bigger than the defined areas then this causes the pane to scroll downwards so you see ...

45. JOptionPane withour parent frame.    java-forums.org

46. Monogram JOptionPane    java-forums.org

You are only allowed to return one variable from a method, so when it reaches the first return statement it exits the method. Hence, why they are "unreachable". You could try to make firstName, middleName, and lastName global variables so you won't have to return them. Also, I don't see where you are calling that method anywhere in your code. Then ...

47. Switch JOptionPane    java-forums.org

I need to write a switch statement to let user select one operation out of three methods using JOptionPane. The methods are: second, last, first. I think it would be something like this: public static void main(String[] args) { SLF3 Benjamin = new SLF3(); int userSelection; userSelection = JOptionPane.showInputDialog(" "); switch (userSelection) { case 1: Benjamin.second(); break; case 2: Benjamin.last(); break; ...

48. Help with JOptionPane    java-forums.org

I am writing a GUI program to calculate sales tax. I am trying to make it more robust by making it catch an exception of the user enters somthing other than a double. I try to compile this code, but it tells me that on the lines where "JOptionPane" appears, that the compiler cannot find the symbol. Help? Thanks. Java Code: ...

49. computing cylinder volume using JOptionPane    java-forums.org

hi i just started java in community college and writing code is something that is is totally new to me. i have been trying to write a program that computes volume of a cylinder and the problem i riun into is that it compiles ok but when i enter 2 numbers (legnth and radius) in my input pane the prgram crashes ...

50. JOptionPane: HELP FAST!!!    java-forums.org

Hello Everyone, I am doing a mini program for class using JOptionPane. It complies correctly and runs almost correctly. The assignment is to write a program that asks the user to enter 3 test scores. The program should display each test score, as well as the average. I am able to create this except for the fact what ever score the ...

51. RE: JOptionPane Prompt    java-forums.org

Hello, I had a quick question for some of you experts out there. I have an assignment where I have to set up a loop that sets it so that you cannot input a negative number if (x < 0) { JOptionPane.showMessageDialog(null, "Cannot be negative, try again"); JOptionPane.showInputDialog("How tall are you"); } When I put two negative numbers in a row, ...

52. JOptionPane Basics    java-forums.org

53. Help with getting file and doing something with it from JOptionpane    java-forums.org

Hello. I am trying to get the below code to take the filename that is entered from the end user and then get it to do the task that that user selects if it is 1,2,3,4 When I get the menu to appear it lets me insert the filename but doesnt prompt me for the coices 1-4. I am missing alot ...

54. Problem with JOptionPane    java-forums.org

// demonstrates reading an unout file import Barnfield.Dialogs; import java.io.*; class ShowFile{ public static void main(String args[]) throws IOException{ int i; FileInputStream fIn; String fileName = "C:\\users\\chris\\desktop\\java\\week 12 - IO\\text.txt"; try{ fIn = new FileInputStream(fileName); // opens the file for input } catch (FileNotFoundException exc){ System.out.print("File not found"); return; //exit from call to main } // read bytes untill EOF is ...

55. JOptionPane    java-forums.org

Ok so i changed some stuff around on this... I want to confirmdialog to ask the user to either continue the program and go threw the loop, or enter another loan amount, or exit... This is what i got so far but its wrong. I cant seem to find much about this online. Java Code: import javax.swing.*; public class MortgageApp3 { ...

56. joptionpane quizz , improve my code ....    java-forums.org

import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { String no = null; no = JOptionPane.showInputDialog("sum of 229+566="); if ( no == null ? "sum" == null : no.equals("795")) { JOptionPane.showMessageDialog(null, "correct " + no); } else {JOptionPane.showMessageDialog(null, "wrong " + no);} String nom = null; nom = JOptionPane.showInputDialog("mul of 229x566="); if ( nom == null ? "sum" ...

57. Empty JOptionPane when called from ChartProgressListener?    jfree.org

Empty JOptionPane when called from ChartProgressListener? by SaraB Mon Jun 16, 2008 8:53 pm I have an application that features an XYScatterPlot created from data in a mySQL database (usually 10k - 300k datapoints). In general, everything works fine, the data plots well, zooms, can be modified, etc. etc. (I don't really wish to include all the code here because ...

58. JOptionpane    forums.oracle.com

59. School Project Help (StringTokenizer/JOptionPane/etc)    forums.oracle.com

Hey again guys, I've had great help in the past here and im hoping you guys will be able to aid me again. This is very similar to my last project where I created a program, thank God, with help from you guys and information online and in the textbook, using the JOptionPane to ask for some information, perform some calculations, ...

60. Force scroll bar on JOptionPane?    forums.oracle.com

Is there a way to force some type of scroll bar in a JOptionPane.INFORMATION_MESSAGE ? I have written a program that figures the first 1000 prime numbers as required by my instructor. However, when the final output box prints it runs off the screen. I'm some what of a net freak and would prefer to set a fixed value for the ...

61. Help:Arrays and JOptionPane    forums.oracle.com

62. JOptionPane Question    forums.oracle.com

I have a sneaking suspicion that a JOptionPane is not really suitable for your task. You might want to investigate the use of a JDialog (okay, I supose you could use a custom JOptionPane but it seems a little kludgy.) with 2 fields for logging in to the application (which I'm a-guessin' is what you are doin').

63. LINEAR SEARCH AND JOPTION PANE.    forums.oracle.com

Well does it run or not ? if it runs like it should be then nothing is wrong. If it doesnt then something is wrong! But that aside, if you want to use a JOptionPane why cant i see it anywhere in you code, the code that you should have posted in code tags so it would be actually readable

64. JOptionPane help please - I'd be v. grateful    forums.oracle.com

65. JOptionPane    forums.oracle.com

I believe I am running Java 1.4.2_15 and studying Java on my own. An example I have tried to run has revealed that the JOptionPane class is not on my PC. Please help me fix that. I saw in the zip file several classes but I just do not find the JOptionPane class anywhere. I did an internet search and I ...

66. How to make a clickable link into a JOptionPane    forums.oracle.com

Yes.... You can put other things besides strings into JOptionPanes. Such as you can put a JEditorPane that displays some HTML, which can in turn have links in it. Or buttons that look like links. But I've also had problems in modal dialogs in some cases where clicking the links in HTML doesn't work correctly (the HyperTextEvent doesn't get fired). As ...

67. JOptionPane Question???    forums.oracle.com

69. JOptionPane Problem    forums.oracle.com

70. JOptionPane    forums.oracle.com

71. i need an example about JOptionPane?    forums.oracle.com

72. i need your help!!! JOptionPane!    forums.oracle.com

73. JOptionPane optionTypes    forums.oracle.com

74. Self terminating JOptionPane?    forums.oracle.com

Don't know about JOptionPane since it constructs itself and maybe does not provide access to its components. But if you have a reference to the button that closes the dialog or to the dialog itseld you can schedule a task (check javax.swing.Timer and java.util.Timer) that can invoke doClick() on the button or dispose() for the dialog or whatever other method you ...

75. javax.swing.JOptionPane    forums.oracle.com

76. Needing help organizing JOptionPane outputs    forums.oracle.com

Evening all, I'm trying to have a few variables whose info I get from JOptionPane such as Id, Name, Address etc.. to print out in a finished JOptionPane. The program I have so far prints it out nice and neat in the cmd window, but I havent had to make it printout in a JOptionPane window all nice and neat. Would ...

77. can we use JOptionPane method in Enum class...    forums.oracle.com

guys i want to give month in runtime in my code below and for this i use JOptionPane method but it is not working.can someone guide me for this and let me knw another method to give data in runtime in enum.thnx.here is my code below enum Month { JANURAY,FEB,MARCH,APRIL } class EnumExample1 { public static void main(String args[]) { Month ...

78. JOptionPane ?    forums.oracle.com

Makes me wonder if you wrote the original code in the first place. So long story short, did you? If you answered yes then i'm flawed as to why you can't prompt a user to enter yes or no, then invoke a method if the user input yes after writing the code in your original post. Mel

79. Using JOptionPane    forums.oracle.com

Is there a way to do so? I know you can accept strings, but I can't find a way to accept a string and then convert to boolean - but that can lead to its own problems of mistakes and what not. Eitherway, is there a simple way to either give the user a choice of true/false, or convert it to ...

80. JOptionPane    forums.oracle.com

Hello guys, I have started learning Java programming and as I learn I write some small programs to test what I have learned. I wrote a program that will open a small window and ask the user to input a string of characters. Then the program counts the characters and displays the total number. It all works good.But this is my ...

81. JOptionPane    forums.oracle.com

82. odd joptionpane behavior    forums.oracle.com

I use a joptionpane.showoptiondialog. The odd thing is that every once in awhile the frame is visible, but not the content pane. Now, the content pane is still functional, the buttons all work. But it is transparent, like a window. Does this problem sound familiar? I can upload a screen shot if that helps explain.... Thanks in advance for any help. ...

83. JOptionPane    forums.oracle.com

84. Quick JOptionPane question    forums.oracle.com

85. \t in JOptionPane    forums.oracle.com

I want to insert a tab in a JOptionPane.showMessageDialog but he won't display that tab (on Windows). So like this: JOptionPane.showMessageDialog(null,"\ttest\ttest2"); If I transform it into a System.out.println(...); then I get my expected tabs (but I want a Message dialog :p) But when I execute the same code on a Mac the output is shown as expected (so with the expected ...

86. Need help with JOptionPane.    forums.oracle.com

87. javax.swing.JOptionPane    forums.oracle.com

im using READY TO PROGRAM with java i unno what jdk that is sorry but umm here is the error meassage when i try to compile it. javax/swing/JOptionPane is either a misplaced package name or a non-existent entity. When i use this exact code at my schools computers it seems to work fine. so i unno ty for your help all ...

88. JOptionPane IF statement?    forums.oracle.com

89. Using JOptionPane to exit program & Using toString method    forums.oracle.com

well, for the toString - I have to print out the info inside the array -- am I right in thinking that the only way to do this is to pass in the array ?? and i have 2 other files that go with this program . . . I just want to know if there is a way to make ...

90. JOptionPane is not showing    forums.oracle.com

I am having a relatively odd problem, on my laptop I have been writing basic Java programs for awhile and I have had no problems, but now dialogs are no longer working. My different programs will stop waiting for a response from the dialog, such as 'Ok' or 'Cancel;' however, the dialog does not appear to enable one to answer. My ...

91. JOptionPane issue    forums.oracle.com

92. JOptionPane, where does it come from?    forums.oracle.com

94. Reading Integer using JOptionPane    forums.oracle.com

I'm trying to write a Java program using JOptionPane dialog/display boxes that reads an integer and checks whether it is even using true/false statements. I also want the program must check if the number the user entered is between 1 and 1000. I haven't found alot of help in the book I have, so I'm hoping somone has some example modules. ...

95. Problem With JOptionPane - Pls Assist    forums.oracle.com

I am trying to create a quiz using JOptionPane.showInputDialog - My question is how can i track how many correct answer that the user has choosen. The question is in String format --> choices but my variable --> correctAns to check against it is in integer e.g choices[0] = "A"; choices[1] = "B" choices[2] = "C"; choices[3] = "D" int correctAns ...

96. Joption Pane question    forums.oracle.com

97. JOptionPane    forums.oracle.com

98. how to override JOptionPane's location    forums.oracle.com

99. Newbie question.By using JOptionPane    forums.oracle.com

100. JOptionPane troubles    forums.oracle.com

Your best bet here is to show us more of your code, enough so that we can compile and run the code, and see the problem ourselves. We don't want to see all of it, but rather you should condense your code into the smallest bit that still compiles, has no extra code that's not relevant to your problem, but still ...