Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Modal dialog box and request focus

 
Sumana Reddy
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a modal dialog box.When ever I make the dialog box visible I need to request the focus for a particular button.
below is the description of how I tried to achieve the functionality
I can request the focus by calling requestFocus method.We should request the focus only when the component is visible i.e only after i make the dialog box visible.But when a modal dialog box is visible it blocks the application and the requestFoucs method is not executed as long as the dialog is visible.
So in order to solve this problem I decided not to make my dialog modal during creation time.When I make my dialog visible, First i will request the focus and then make the dialog modal.But once the dialog is visible the modal concept is not working.thoght the setModal() is executed and the dialog.isModal() returns true But somehow the dialog is not modal on the application.
So I tried to implement this modal functionality as you suggested i.e enabled and disabling the parent.That works pretty fine.But when I close the dialog box The parent frame is hidden and someother window that's on task bar will be in the front.
So when I close the dialog I call the parent.toFront() to make it appear infront of all windows.when the dialog is closed the parent frame will come to front after some flickering.That flickering is real bad.
Is there any better solution for the above problem.
Thanks Sumana
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you're using a button you could use the setDefaultButton() method of JRootPane...

Here's a short example program showing how to use setDefaultButton() :



If you need to request focus for another kind of component, you may need to do so in a ComponentListener's componentShown() method attached to the dialog.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic