I'm taking a beginning Java class and
an assignment requires that I write a class to represent a JPanel with buttons to
increment and decrement a value and a label to display the value. Then, I have to create
a separate class which instantiates the panel and adds it to a frame. I'm trying to have
the frame resize to fit the size of the panel by running the pack method. I try to call
the frame's pack method by using:
SwingUtilities.getAncestorOfClass(JFrame.class,
this).pack()
I get a
"cannot find symbol - method pack()" error. The getAncestorOfClass is definitely
returning a JFrame, and it is the correct JFrame. When I run the pack method from inside
the driver class where the JFrame is created, there are no problems. Any ideas why it
can't find the pack method? Is it because I'm trying to run this from a separate class
file? I also can't access some other JFrame methods such as getContentPane, but I
am able to access some others such as add.
Huh?
No comments:
Post a Comment