Search code examples
javaswingjbuttondefaultbutton

Set the default button in jpanel depending on focus.


i have several JPanels which each implement their logic, buttons and fields on their own. This panels are all added on a JFrame but sometimes on another Panel which is then added on the frame...

What i want to achive is that hte default button is the ok button for panel1 when any successor of it has the focus. And same for all the others...

How to do this? The panels itself dont have a JRootPane and I don't want to bother the Frame with the logic for that.

Every tip is welcome ;). Thanks in advance.


Solution

  • i have several JPanels which each implement their logic, buttons and fields on their own. This panels are all added on a JFrame but sometimes on another Panel which is then added on the frame...

    What i want to achive is that hte default button is the ok button for panel1 when any successor of it has the focus. And same for all the others...

    The panels itself dont have a JRootPane and I don't want to bother the Frame with the logic for that.

    • I think you are right, to use CardLayout