Home Answers Viewqa Swing-AWT JFrame components printing

 
 


ravi kumar
JFrame components printing
0 Answer(s)      3 years and 2 months ago
Posted in : Swing AWT

hi sir
thanks a lot for your reply...
but i go through the link that you have specified
http://www.roseindia.net/java/example/java/swing/Print.shtml

and downloaded the codes and compiled it got errors
and i removed that error and i executed program
when i press print button it displays these
errors

at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

so what can i do to avoid and function it properly

and i have altered the PrintExample content like this

public class PrintExample extends JFrame implements ActionListener {
public static void main(String[] args) {
new PrintExample();
}

public PrintExample() {
super("Printing Swing Components");
WindowShow.setNativeLookAndFeel();

Container content = getContentPane();
JButton printButton = new JButton("Print");
printButton.addActionListener(this);
JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(Color.white);
buttonPanel.add(printButton);
content.add(buttonPanel, BorderLayout.SOUTH);
DrawingPane drawingPanel = new DrawingPane();
content.add(drawingPanel, BorderLayout.CENTER);
setSize(520,500);
setVisible(true);
}

public void actionPerformed(ActionEvent event) {
PrintableDocument.printComponent(this);
}

class DrawingPane extends JPanel {
private int fontSize = 15;
private String message = "Name";
private int messageWidth;

public DrawingPane() {
setBackground(Color.white);
Font font = new Font("Serif", Font.PLAIN, fontSize);
setFont(font);
FontMetrics metrics = getFontMetrics(font);
messageWidth = metrics.stringWidth(message);
int width = messageWidth*5/3;
int height = fontSize*3;
setPreferredSize(new Dimension(width, height));

}

public void paintComponent(Graphics g) {

super.paintComponent(g);
Graphics2D graph = (Graphics2D)g;
graph.drawRoundRect(10, 10,480,380,10,10);
graph.drawLine(10,60 ,490,60);
graph.drawLine(320, 60, 320, 390);
graph.drawLine(10, 345, 490, 345);
graph.setPaint(Color.black);
graph.drawString("NAME :", 15,30);
graph.drawString("COURSE :",15 ,55 );
graph.drawString("CLASS :",270, 55);
graph.drawString("Amount :", 15,110);
graph.drawString("Balance :", 15,150);
graph.drawString("Total :", 15,340);
graph.drawString("Recieved :", 15,380);




}
}
}

does it print the rectangle lines and strings what i mentioned above sir
and also please go through the print button error sir please i need it for my complteion of my little project thanking you a lot sir
View Answers









Related Pages:
JFrame Components Printing - Swing AWT
JFrame Components Printing  hi sir i am doing a project so i am working in netbeans i have to print a JFrame it contains Labels and few textboxfields so i want to take the whole JFrame contents for printing so would you
JFrame Components Printing - Swing AWT
JFrame Components Printing  hi sir thanks a lot for your reply... PrintExample() { super("Printing Swing Components... this public class PrintExample extends JFrame implements ActionListener { public
JFrame components printing - Swing AWT
JFrame components printing  hi sir thanks a lot for your reply... PrintExample extends JFrame implements ActionListener { public static void main(String[] args) { new PrintExample(); } public PrintExample() { super("Printing
JFrame components printing - Swing AWT
JFrame components printing  hi sir thanks a lot for your reply... PrintExample extends JFrame implements ActionListener { public static void main(String[] args) { new PrintExample(); } public PrintExample() { super("Printing
Printing 2 arrays
Printing 2 arrays  Hi, I have 2 arrays: String [] head = {"Name", "Date of birth", "PPS number"}; String [] personal= {value1, value2, value3}; I... not work since I'm using GUI (JFrame) but below workaround worked for me
JFrame
JFrame  write an application with a JFrame that five labels describing reasons that a customer might not buy your product(for example "Too expensive") every time the user clicks a Jbutton, remove one of the negative reasons
jframe
jframe  Create a JFrame for the Summervale Resort. Allow the user to view the information about different rooms available, dining options and activities offered. Include at least two options in each menu and display appropriate
JFrame
Jframe. How can i do it. Please help me to do it. Or what else can i have
Lost Using Swing Components
*; import java.awt.event.*; public class JEMail extends JFrame implements
Lost Using Swing Components
*; import java.awt.event.*; public class JEMail extends JFrame implements
Lost Using Swing Components
. import java.awt.*; import java.awt.event.*; public class JEMail extends JFrame
Java Print the all components
JFrame implements ActionListener { Vector data; JTable table; JLabel banner
Lost Using Swing Components(2)
Lost Using Swing Components(2)  Here is the code block corrected: //Insert missing code here. import java.awt.*; import java.awt.event.*; public class JEMail extends JFrame implements ActionListener { //Insert missing code
Lost Using Swing Components(3)
Lost Using Swing Components(3)  Hello, I sound like every other newbie but I desperately need help. I have to write an application for the WebBuy... java.awt.*; import java.awt.event.*; public class JEMail extends JFrame implements
printing in swing
printing in swing  How can i print payslip in swing
Serializing GUI Components Across Network - tutorial
Serializing GUI Components Across Network 2001-03-14 The Java Specialists' Newsletter [Issue 013a] - Serializing GUI Components Across Network Author... Components Across Network When Swing came out, I was puzzled by the following
Placing components on each other - Java Tutorials
Placing components on each other 2002-02-15 The Java Specialists' Newsletter [Issue 041] - Placing components on each other Author: Dr. Heinz M. Kabutz... been playing golf instead of writing newsletters *blush*) Placing components
Components
Components in Flex4 is the simple extension of the components of Flex3. In this section, you will learns different types of spark components to be used in Flex4. Here is the list of spark components
JFrame - Window
. public class MyExample extends JFrame { //... Declare components... Java: JFrame - Window Description The javax.swing.JFrame class is used... pane or menu bar. Constructors You can create a frame like this: JFrame w
applet printing
applets gridwise and in each applet i am drawing some graph so while printing whole... but while printing it is not getting printed on paper and rest everything it is printing
printing in java
printing in java  hello i want to print a jInternalframe containing some lebels,but my printer sent me a paper with the following written on it: "www.java2s.com" please what is the problem
Refresh JFrame
Refresh JFrame  How to refersh a JFrame and its componets
Printing stars
Printing stars  I am a beginer and i have one assignment which couldnt give me any idea how to do it..The Question is "Get a string "001222014654" and print o/p as 0 - * 1- ** 2- * 4- ** 5-* 6-* I dont know how to split
Create Layout Components in a Grid in Java
Create Layout Components in a Grid in Java   ... layout components with the help of grid in Java Swing. The grid layout provides the facility to arrange some created GUI components for the frame. The grid
Hiding a JFrame
javax.swing.*; import java.awt.event.*; class PassData extends JFrame { JTextField... java.awt.*; import java.awt.event.*; class NextPage extends JFrame { NextPage
Hiding a JFrame
javax.swing.*; import java.awt.event.*; class PassData extends JFrame { JTextField... java.awt.*; import java.awt.event.*; class NextPage extends JFrame { NextPage
Sharing a Table Model between JTable Components
Sharing a Table Model between JTable Components... how to share a table model between JTable components. Whenever, you want to do for sharing the resources between the JTable components, a table model
Java program for printing document
Java program for printing document  can u send me the java program for printing the office document? email: ibrahimbest@gmail.com
Java Swing : JFrame Example
holds all the non-menu components displayed by the JFrame. The content pane...Java Swing : JFrame Example In this section, you will learn how to create a frame in java swing. JFrame : JFrame class is defined in javax.swing.JFrame.
printing java series
printing java series  * *** ***** ******** ***** *** *   Post the format properly
Components
Java NotesComponents Components (also known as "widgets") are the basic..., ... Components are placed in a container (eg, JPanel). The visual arrangement of the components depends on the container's layout. When the user does
Orientating Components Right to Left,java newsletter,java,tutorial
Arranging Components We often arrange the components either from left to write or right to left. For the components orientation we uses Layout Manager... of these Layout Managers arranges the components in some there specific way
Printing server information
Printing server information  Hello, I am learning PHP language. I trying to fetch the server Information Print. How could i will printing the server... connected to your PC? This it best example for the Printing server Information
how to reset JFrame
how to reset JFrame  how to reset JFrame
printing example - Java Beginners
printing example  Is it possible to print java controls using print method? My problem is to print a student mark list using java? The mark list should like that of university mark list
Java Printing - Java Beginners
Java Printing  Can anybody plz help in giving the code for printing the contents of JPanel.. It contains JLabels and JTextFields only.. Plz.. Its urgetn.. Printing means sending the document to the Printer..  Hi Friend
refresh checkbox jframe
refresh checkbox jframe  How to refresh checkbox button in JFrame
how printing landscape?
how printing landscape?  I have code which print some data from data base with "drawString()" and it works correct when I chose "Portrait" from "Print Dialog", but it does not work if chose "Landscape". Is any way to print
printing hollow square
printing hollow square  Write an application (PrintingSquares.java) that prompts the user to enter the size of the side of a square, then displays a hollow square of that size made of asterisks. Your program should work
jframe background color not showing
jframe background color not showing  jframe background color is not showing. please suggest.   Just add the background color to JPanel and then add it to JFrame. For example .. JFrame myFrame = new JFrame(); JPanel
Printing ArrayList - JSP-Servlet
Printing ArrayList   I have a code in servlet like this ArrayList total = new ArrayList (); session.setAttribute("efg",total); RequestDispatcher rd; rd = request.getRequestDispatcher("/checkout.jsp"); rd.forward
printing series in java
printing series in java  1 123 12345 1234567 12345 123 1   Here is a code for the following pattern: 1 123 12345 1234567 12345 123 1 class Pattern{ public static void main(String[] args
jumping frame jFrame to jInternalframe
jumping frame jFrame to jInternalframe  Afternoon sir, I want to ask... and sub menu(employee). in Form Login(jFrame) have username(textfield1) and password(passwordfield1), in Menu(jframe) have Menu employee(jMenu),creaby(jlabel1
Java Interview Questions - Page 9
;    Question: Which package has light weight components? Answer:  javax.Swing package. All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components
JFRAME - Java Beginners
javax.swing.*; import java.awt.event.*; public class MenuExample extends JFrame
printing the following output using for loop
printing the following output using for loop  1 2 3 3 4 5 4 5 6 7

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.