• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with JDialog and JOptionPane

 
Akhil Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

need your support here. i tried everything i could, to get this work. but no success.


I have JFrame, which contains some menus on menu bar, one such menu is "Settings" which contains "Configuration" as JMenuItem, When clicking on that, i want to show a JDialog/JOptionPane/JFrame, where user can actually enter some values in text fields and click on "OK", these values will be used by JFrame accordingly.

Now the problem is:

1. If i am using JOptionPane's showInputDialog() method, then i am not able to set its Title Bar Icon (by default, it doesn't comes with any icon on its title bar as JFrame does.).

2. If i am using JOptionPane's showInputDialog() method, I am not able to put a JPanel inside it which contains properly formatted input fields.

3. If i am using JFrame, so that i can put any JPanel and any user input stuff, then , it comes with minimize and maximize buttons on top-right, which i dont want, since i am intension is to use it as a dialog for just getting input from the user.

4. secondly, if i use JFrame, then the new Jframe which comes up, can loose focus , when user clicks on main JFrame which contains Jmenu, i dont want user to actually able to access that main JFrame, untill he has provided any input which i am asking for (2-3 input fields) or unless he has explicitly clicked on "Close" button of that JFrame which is acting as a dialog. I am not getting any way to do it.

can someone please help.

Regards,
Akhil
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Akhil Jain:
2. If i am using JOptionPane's showInputDialog() method, I am not able to put a JPanel inside it which contains properly formatted input fields.

Use showConfirmDialog instead, with your JPanel as the second parameter (message) and JOptionPane.OK_CANCEL_OPTION as option type. Then check if the return value equals JOptionPane.OK_OPTION to see whether the user pressed OK, then get the values from the panel.
 
Akhil Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

I liked the idea. it worked great..

Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic