Originally posted by iloveOSX:
[b]hello, i am learning java and typed in the following example from a learningjava book.What should happen is a window with a button should be drawn. the screenshot of the results(windows) shows a small button on a window. under OSX though the button fills the ENTIRE window.
does this happen with you? the commentted lines produced the same results. is swing broken of osx? or is it a beginners mistake?
[b]
To layout, position and size widgets, Java uses a concept called LayoutManagers. Look this up in your book. What this means is that most of the time (ideally, never) won't explicitly be sizing your widgets like your trying to do here.
My guess is that the frame's default layout manager lays out your component a little differently than what it has done for the author of your book. Strange as it may seem, this is not nescessarily wrong.
When you've understood the concept of layout managers you'll understand that the example I'm about to give you is "wrong". But try doing the following modification to your code, and see if you now get the result you want (be sure to remove the comments you've made in your code, so that it's just like the example before you insert my modification):
Code:
JFrame frame = new JFrame("This is the title...");
// --> Insert the following line
frame.setLayoutManager(null);
// <--
frame.setSize(300,300);
I haven't got a computer with java on it right now, so I'm not entirely sure that this will work.
[This message has been edited by scotty (edited 03-27-2001).]