This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Confusion" Watch "Confusion" New topic
Author

Confusion

Khadija Lokhandwala
Ranch Hand

Joined: Sep 11, 2007
Posts: 33
Hi, I am learning Swing and was really stuck wit this
I have a JMenu Class named "Vertical Menu" which I have customised.
I have over ridden the setFont() method and it is working fine. I wanted to override the setPreferredSize() method too, but size was not reflecting. So I placed it in the "Vertical Menu"'s constructor. And it worked.

The question is: why did setPreferredSize() method work after placing it in the constructor?? if so then, how does the overridden method work.

P.S : setFont() was invoked on the VerticalMenu Object
i.e i did not do
VerticalMenu menu = new VerticalMenu();
menu.setFont();

Thank You


If you ask me anything I don't know, I'm not going to answer.<br />--Yogi Berra
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if I'm reading this correctly, the method you override should be
getPreferredSize()

putting setPreferredSize in the constructor executes that call
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Confusion
 
Similar Threads
Font
Sub JPanel Size
Changin font in a JTextArea
Changing fonts in applets?
JScrollPane doesn't work?