Results 1 to 1 of 1
Thread: Printing Graphics to a 8.5 X 11
- 03-01-2011, 09:28 PM #1
Senior Member
- Join Date
- Dec 2010
- Location
- Indiana
- Posts
- 202
- Rep Power
- 3
Printing Graphics to a 8.5 X 11
My program....
There is a blank white page of a 8.5 X 11 paper with a 3X4 grid on it.
There is a user area to create grids on the right side. SO basically 2 JPanels EAST and WEST.
When the user clicks the "ADD" button it adds the current grid to one of the 3X4 units.
There is a print button - when u click print it prints basically what you see on the left side minus a few grid lines and indention.
**** MY QUESTION *****
Since the left side is just a preview it is also scalable to the user. Which means if I copy that Graphics object from the preview to the Printable print method. It is hard to scale it right for print.
So I figure I would make one central reference graphic object and copy from that. The problem is I cannot use a Graphic object that hasnt actualyl been painted on screen. How can I do this?
here is reduced SSCCE version of code showing when I remove (comment out) the mainGraphic the scaled preview on the right doesnt show anymore.
Java Code:import javax.swing.*; import java.awt.*; import java.awt.print.*; public class TransferGraphics { JFrame frame = new JFrame(); JPanel mainPanel = new JPanel(); MainGraphic mainGraphic = new MainGraphic(); PrintPreview printPreview = new PrintPreview(); TransferGraphics() { mainGraphic.setPreferredSize(new Dimension(850, 750)); printPreview.setPreferredSize(new Dimension(400, 640)); //mainPanel.add(mainGraphic, BorderLayout.WEST); mainPanel.add(printPreview, BorderLayout.EAST);[COLOR="Red"]How can I display this without displaying mainGraphic first?[/COLOR] mainPanel.setBackground(Color.darkGray); frame.add(mainPanel); frame.setSize(1280, 760); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public class MainGraphic extends JPanel { public void paintComponent(Graphics g) { g.setColor(Color.WHITE); g.fillRect(0, 0, 850, 1100); g.setColor(Color.RED); g.fillRect(0, 0, 50, 50); g.fillRect(55, 0, 50, 50); g.fillRect(0, 55, 50, 50); g.fillRect(55, 55, 50, 50); g.setColor(Color.BLACK); g.fillRect(800, 0, 50, 50); g.setColor(Color.BLUE); g.fillRect(800, 1050, 50, 50); g.setColor(Color.GREEN); g.fillRect(0, 1050, 50, 50); } } public class PrintPreview extends JPanel { public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.scale(.4, .4); mainGraphic.print(g); } } // MAIN METHOD public static void main(String[] args) { TransferGraphics tg = new TransferGraphics(); } }
Similar Threads
-
printing string backwards and printing every other
By droidus in forum New To JavaReplies: 22Last Post: 03-10-2011, 09:17 AM -
Drawing a graphics onto another Graphics ?
By Ziden in forum Java AppletsReplies: 0Last Post: 01-08-2011, 07:30 PM -
Help with 2d graphics please
By xbox_nutter in forum New To JavaReplies: 0Last Post: 04-02-2009, 11:48 AM -
SWT Graphics Example
By Java Tip in forum SWTReplies: 0Last Post: 06-28-2008, 09:28 PM -
Problem in printing java graphics
By Mahendra in forum Java 2DReplies: 0Last Post: 01-23-2008, 12:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks