This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to make default JButton in child class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to make default JButton in child class" Watch "How to make default JButton in child class" New topic

How to make default JButton in child class

Craig Hagerman

Joined: Oct 08, 2001
Posts: 1
How can I make a button the default button?

I have read that I can use


This worked in a test program where there was only one class. However in another program involving two classes I can't get it to work.

Here is a snippet from the simple working class which extended JFrame:

Container contentpane = getContentPane();
JPanel panel = new JPanel();
JButton doit = new JButton("Do It");

But in the second case the JPanel component above is a different class ( And here this technique results in a nullPointer exception at runtime.

class TestPanel extends JPanel
{ public TestPanel()
{ JButton doit = new JButton("Do It");

I also tried other things like:


thinking that that would reference the parent JFrame-extended class, but no luck. (How do you use getParent()?)

Can anyone tell me how to set up a default JButton in such a case?
Craig Hagerman
I agree. Here's the link:
subject: How to make default JButton in child class
It's not a secret anymore!