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:

  1. add label "enter name" gui
  2. add textfield gui
  3. add ok button gui (with actionlistener)
  4. attach actionlistener @ "ok" button
  5. fetch textfield value on "ok" click, return , dispose jdialog

comment post if have questions or remarks.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -