>From the book Mastering Java 2 -1.4 form SYBEX, I have this code
--- snip
public class Picasso extends ExitableJFrame{
Insets insets;
public void paint(Graphics g) {
super.paint(g);
if(insets == null) {
insets = getInsets();
}
g.translate(insets.left, insets.top);
g.fillRect(30,10,200,300);
g.clearRect(50,30,70,50);
g.drawRect(60,50,40,20);
g.drawLine(10,55,250,55);
}
public static void main(String args[]) {
Frame f = new Picasso();
f.setTitle("Picasso");
f.setSize(900,900); // Size of the window !!!
f.pack();
f.setVisible(true);
//f.show(); //Method obsolete ?
}
}
-- end --
But the window is *waaaay too small and none of the graphics get
displayed, when I drag the window to a larger size, I can see the the
graphics are there, but when I let go of the mouse button the images no
longer appear on the window.
How can I get Java to display the window in a size that would be more
convenient?
TIA.
Oliver Wong - 13 Sep 2005 19:01 GMT
> >From the book Mastering Java 2 -1.4 form SYBEX, I have this code
> public class Picasso extends ExitableJFrame{
[snip]
> public static void main(String args[]) {
> Frame f = new Picasso();
[quoted text clipped - 8 lines]
> But the window is *waaaay too small and none of the graphics get
> displayed
Not sure what an ExitableJFrame is, but if it's anything like a JFrame,
then pack() will resize the window, so the setSize(900,900) called earlier
is essentially useless.
- Oliver
Roedy Green - 13 Sep 2005 20:45 GMT
> f.setSize(900,900); // Size of the window !!!
> f.pack();
pack says shrink the window to the smallest possible size that will
still hold everything.
You meant to say f.validate() which leaves the window at 900,900 and
just adjusts the components inside.
See http://mindprod.com/jgloss/validate.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.