Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Modal dialog box and request focus

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic