[java] Resizing window?

Started by
8 comments, last by CaptainJester 18 years, 2 months ago
Im using jpanel and jframe and im trying to scale my program to the window when I resize it(not necessarly full screen). Can someone help me?
Advertisement
You want the panel to stretch to the size of the frame, or what? Need some specifics, please...
yes I am drawing something on my window and when I make the window bigger the stuff that I drew doesn't scale up to the new window size.
yes I am drawing something on my window and when I make the window bigger the stuff that I drew doesn't scale up to the new window size.
What layout are you setting on the frame? If you're setting any layout (such as say, FlowLayout), then the panel within the frame won't size to the bounds of the frame. What you want to do is not set any layout at all on the frame (just leave it with its default) and you should get the desired result.
wow!!!! that worked and was super easy. Thanks
Now, I have one more problem. I have a button on my window for print. How do you print to the printer your screen or your window?
1. Implement the java.awt.print.Printable interface
2. Invoke java.awt.print.PrinterJob.getPrinterJob() to get an instance of a printer job.
3. java.awt.print.PrinterJob.setPrintable(...) passing in your Printable object.
4. java.awt.print.PrinterJob.printDialog()

It's been a while since I have done it, but that is close. You can look at all the stuff under java.awt.print.* package to see how it works.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
Quote:Original post by CaptainJester
1. Implement the java.awt.print.Printable interface
2. Invoke java.awt.print.PrinterJob.getPrinterJob() to get an instance of a printer job.
3. java.awt.print.PrinterJob.setPrintable(...) passing in your Printable object.
4. java.awt.print.PrinterJob.printDialog()

It's been a while since I have done it, but that is close. You can look at all the stuff under java.awt.print.* package to see how it works.


hehe, if only it were that easy.

There are some tutorials on printing on the Java website. I suggest you look those up. While going through them, they don't mention the fact that you should be prepared to print any page of your document at any time, even if you don't anticipate the need to print pages out-of-order. The printing API ends up actually calling the print method TWICE for the first page. This caused a problem for me when I first used it as I was consuming my text as I was printing it. I was rather confused when page 1 would never come out.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Quote:Original post by capn_midnight
hehe, if only it were that easy.

There are some tutorials on printing on the Java website. I suggest you look those up. While going through them, they don't mention the fact that you should be prepared to print any page of your document at any time, even if you don't anticipate the need to print pages out-of-order. The printing API ends up actually calling the print method TWICE for the first page. This caused a problem for me when I first used it as I was consuming my text as I was printing it. I was rather confused when page 1 would never come out.


I have only printed images, so it was that easy for me. I always checked what page I needed to print and printed accrodingly.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]

This topic is closed to new replies.

Advertisement