java - Password Field in a JOptionPane | DaniWeb Menu Menu DaniWeb Log In Sign Up Read Contribute Search Search Password Field in a JOptionPane Home Programming Forum Software Development Forum Discussion / Question Ghost 0 Posting Whiz 17 Years Ago Hi everybody, I was wondering if it is possible (and if it is, how to do it) to put a JPasswordField into a JOptionPane. Thanks in advanced, C++ java 0 0 Share 2 Contributors 10 Replies 147 Views 1 Day Discussion Span Latest Post 17 Years Ago Latest Post by server_crash Recommended Answers Answered by server_crash 64 in a post from 17 Years Ago I think JDialog is the best to use when puting custom components like that in. Jump to Post Answered by server_crash 64 in a post from 17 Years Ago Here is an example, but remember this is just an inner class. class processCylinderDialog extends JDialog implements ActionListener  { 	 JLabel lblRadius; 	 JLabel lblHeight; 	 JTextField txtRadius; 	 JTextField txtHeight; 	 JButton btnDone; 	  	 JDialog dlg; 	  	 public processCylinderDialog() 	 { 		 		 JPanel panelOne = new JPanel(); 		 lblRadius = new JLabel("Radius"); 		 txtRadius = new JTextField(10); … Jump to Post Answered by server_crash 64 in a post from 17 Years Ago Thank you very much, server_crash!!! Your very welcome, and if you need any further help just let me know, or Pm me. Jump to Post All 10 Replies server_crash 64 Postaholic 17 Years Ago I think JDialog is the best to use when puting custom components like that in. 0 0 Share Ghost 0 Posting Whiz 17 Years Ago can you please explain how to use JDialog??? Thanx in advanced, C++ 0 0 Share server_crash 64 Postaholic 17 Years Ago Here is an example, but remember this is just an inner class. class processCylinderDialog extends JDialog implements ActionListener  { 	 JLabel lblRadius; 	 JLabel lblHeight; 	 JTextField txtRadius; 	 JTextField txtHeight; 	 JButton btnDone; 	  	 JDialog dlg; 	  	 public processCylinderDialog() 	 { 		 		 JPanel panelOne = new JPanel(); 		 lblRadius = new JLabel("Radius"); 		 txtRadius = new JTextField(10); 		 panelOne.add(lblRadius); 		 panelOne.add(txtRadius); 	 		 JPanel panelTwo = new JPanel(); 		 lblHeight = new JLabel("Height"); 		 txtHeight = new JTextField(10); 		 panelOne.add(lblHeight); 		 panelOne.add(txtHeight); 		 		JPanel panelThree = new JPanel(); 		btnDone = new JButton("Calculate"); 		btnDone.addActionListener(this); 		panelThree.add(btnDone); 		 		  		 dlg = new JDialog(); 		 dlg.setResizable(false); 		 dlg.getContentPane().add(panelOne); 		 dlg.getContentPane().add(panelTwo); 		 dlg.getContentPane().add(panelThree); 		 dlg.setTitle("Cylinder Volume"); 		 dlg.getContentPane().setLayout(new FlowLayout()); 		 dlg.setSize(350,300); 		 dlg.setVisible(true); 	 } 	  	 public void actionPerformed(ActionEvent ae) 	 { 		 getInfo(); 	 } 	 public void getInfo() 	 { 		 if (txtRadius.getText() != null && txtHeight.getText() != null) 		 { 	   try 	   { 		 double cylRadius = Double.parseDouble(txtRadius.getText()); 		 double cylHeight = Double.parseDouble(txtHeight.getText()); 		 double cylVolume = Math.PI * cylRadius * cylRadius * cylHeight; 		 txtResult.setText(dec.format(cylVolume) + ""); 	   } 	   catch(NumberFormatException nfe) 	   { 	   } 	} } You can see that it is just like creating a class that extends JFarme with a few modifications. When you want to display this dialog, you call it like this: new className(); 0 0 Share Ghost 0 Posting Whiz 17 Years Ago Thank you very much, server_crash!!! 0 0 Share server_crash 64 Postaholic 17 Years Ago Thank you very much, server_crash!!! Your very welcome, and if you need any further help just let me know, or Pm me. 0 0 Share Ghost 0 Posting Whiz 17 Years Ago Actually, that didn't work!! Is there any other way (Preferably in JOptionPane)? 0 0 Share Ghost 0 Posting Whiz 17 Years Ago regard previous message - i forgot to put in: new className(); 0 0 Share server_crash 64 Postaholic 17 Years Ago Why don't you post your code, preferably all of it, but most importantly the JDialog inner class and where you call it. 0 0 Share Ghost 0 Posting Whiz 17 Years Ago thanx - but the code's working now. I have one more question: Is there a way to figure out which character is most common in a string? 0 0 Share server_crash 64 Postaholic 17 Years Ago Here's a common example: static int countChars( String str, char searchChar ) {                   // Count the number of times searchChar occurs in                   // str and return the result.                 int i;     // A position in the string, str.                 char ch;   // A character in the string.                 int count; // Number of times searchChar has been found in str.                 count = 0;                 for ( i = 0;  i < str.length();  i++ ) {                     ch = str.charAt(i);  // Get the i-th character in str.                     if ( ch == searchChar )                        count++;                 }                 return count;             } 0 0 Share Facebook Like Twitter Tweet Reply to this topic Be a part of the DaniWeb community We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge. Sign Up — It's Free! Related Topics java uses or overrides a deprecated API?? 4 Java.io help!!! 13 cannot find anything on this assaignment 3 Help with a java program home work assignment 1 I can't implement a word count into my text editor (JAVA) 1 New to C++, need help 14 Trying to open explorer inside my java window 2 Need help with java string.format (prepayment calculation) 2 Really quick G2++ question! 2 Two basic java questions 2 Help: need feedback on my Java assignment about thread sleep. It's already coded. 5 Extracting the highest number with C++ 2 Java novice PLEASE HELP!!! 2 java is supposed to be secure? 6 Sort a dynamic array of structs 8 field lengths (was: help urgent ) 4 code repeatedly 2 ask user 4 a password until correct (=Java) but cant c wots wrong. 2 Bring component forward. 14 Java JDBC ResultSet 2 need help with java 5 Not what you need? Reach out to all the awesome people in our software development community by starting your own topic. We equally welcome both specific questions as well as open-ended discussions. Start New Topic Topics Feed Reply to this Topic This topic is old! No one has contributed to this discussion in over 17 years. Are you sure you have something valuable to add to revive the existing conversation? Consider starting a new topic instead. Otherwise, please be thoughtful, detailed and courteous, and adhere to our posting rules. Edit Preview Message H1 H2 Post Reply Share Post Permanent Link Facebook Like Twitter Tweet Insert Code Block Insert Code Block Search Search Forum Categories Hardware/Software Programming Digital Media Community Center Latest Content Newest Topics Latest Topics Latest Posts Top Tags Topics Feed Social Forums Top Members Community Functions DaniWeb Premium Newsletter Archive Markdown Syntax Community Rules Developer APIs Connect API Forum API Docs Legal Terms of Service Privacy Policy FAQ About Us Advertise Contact Us © 2022 DaniWeb® LLC