java - JoptionPane.showInputDialog Without cancel button and exit handle -
https://i.stack.imgur.com/lrdtn.jpg
i wanna kind of input dialog issue accept int type found `
string[] options = {"ok"}; int selectedoption = joptionpane.showoptiondialog(null, panel, "the title", joptionpane.no_option, joptionpane.question_message, null, options , options[0]);
` i'd handle x(quit button red button close button) because causes exception errors caused
i'm using regex.matcher
at java.util.regex.matcher.gettextlength(unknown source) @ java.util.regex.matcher.reset(unknown source) @ java.util.regex.matcher.<init>(unknown source) @ java.util.regex.pattern.matcher(unknown source)
thanks
existing solution
you use inputdialog of joptionpane
string res = joptionpane.showinputdialog(null, "enter name", "the title", joptionpane.question_message); system.err.println(res);
be aware of result null if user closed dialog or hasn't inserted text.
but solution isn't exactly looking dialog want have. have create own joptionpane.
own solution
i recommend use modal jdialog , remove frame (that causes problems you) with
.setundecorated(true)
or override dispose() in own class handle it
@override public void dispose() { //your code super.dispose(); }
the begin of own class this:
public class myoptionpane extends jdialog { public myoptionpane(dialog owner, boolean modal) { super(owner, modal); this.setundecorated(true); //remove frame } }
go on these steps:
- add label "enter name" gui
- add textfield gui
- add ok button gui (with actionlistener)
- attach actionlistener @ "ok" button
- fetch textfield value on "ok" click, return , dispose jdialog
comment post if have questions or remarks.
Comments
Post a Comment