• Post Reply Bookmark Topic Watch Topic
  • New Topic

Option dialogue box not getting focus  RSS feed

 
Renjila E Rajan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Object[] options = {"Delete","Cancel"};
int confirm=JOptionPane.showOptionDialog(null,"Are you sure you want to delete?","Delete Confirm",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[0]);

I used the above snippet to get a optiondialogue box.its working.But for the first time after running the application,its not getting focus.
please provide a solution.
Thanks in advance
 
Rob Spoor
Sheriff
Posts: 21052
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, and welcome to JavaRanch!

I doubt anyone will be able to figure out your problem given the information presented. You may want to create a very small compilable program that demonstrates your problem and that we can run on our machines. Do this and I predict your odds of getting a helpful solution to be > 90%.

Much luck!
 
Renjila E Rajan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i wanted to have a customised confirm box.since its not possible to customise the javascript confirm box.i tried the above one.I depolyed the war in my Jboss server with the same code .On Running the application ,and tring to click my form button which redirects to the jsp having this code snippet ,the pop up is coming .But its coming in the background for the first time.I 've to press alt+tab to see the confirm box.But for the subsequent requests its working as expected.The problem is only with the first request.
 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure how you want to customize it, but you can change the image, create your own text, insert HTML code to style it. JOption's offer a wide variety of ways to make it look just how you want.
 
Rob Spoor
Sheriff
Posts: 21052
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait, what? Are you trying to use a JOptionPane in a web application? I don't think this is ever going to work properly; the JOptionPane will be shown on the web server, not the client PC.

Maybe you should switch to using an applet instead. Don't use null as the parent then; that will not make the dialog modal. When an applet is shown in a web browser, it has a parent frame that represents the browser. You can get a reference to that as follows:
 
Renjila E Rajan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob
Can you please explain this.
Thanks in advance
 
Rob Spoor
Sheriff
Posts: 21052
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JOptionPane shows its dialogs on the machine where the JVM is running. For web applications, this is the server. Therefore, clients of your web application will not see it. The only reason you are seeing it is probably because the client and server are the same machine.

For showing dialogs on the client you can use JavaScript, an applet or some framework (I'm working with jACOB at the moment at work, but JSF should also be able to help you out).

If you then decide to use an applet, you must pass a proper component to the JOptionPane methods or the dialog will not be modal, and that is something you definitely want. That's what you can use the Frame my code returns for.
 
Renjila E Rajan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,
i am very new to applet.please explain in detail how to get a dialogue box using applet whict pops up on clicking action on jsp page.
Thanks in advance
 
Rob Spoor
Sheriff
Posts: 21052
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The applet would more or less have to replace your JSP. It is possible to interact between an applet and its surrounding page using JavaScript but frankly I couldn't tell you how.

To be honest, I doubt that what you actually want (a Swing dialog instead of a JavaScript dialog) is possible.
 
Renjila E Rajan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,
My doubt is if we are using swing,that will also get run only in serverside right?
 
Rob Spoor
Sheriff
Posts: 21052
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not if it's an applet, but otherwise yes.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!