JFrame components printing
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 completion of my little project thanking you a lot sir
View Answers
Ads
Related Tutorials/Questions & Answers:
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
Advertisements
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
Refresh JFrame
Refresh JFrame How to refersh a
JFrame and its componets
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: please what is the problem
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
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
ModuleNotFoundError: No module named 'Printing'
ModuleNotFoundError: No module named '
Printing' Hi,
My Python... '
Printing'
How to remove the ModuleNotFoundError: No module named '
Printing... to install padas library.
You can install
Printing python with following
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 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 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
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
Removing the Title Bar of a JFrame
Removing the Title Bar of a JFrame How to remove the Title Bar of a
JFrame in Swing Application?
Please check the tutorial Removing the Title Bar of a Frame for the source code and example description.
Thanks
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
printing press training course
printing press training course Hi,
I am beginner in Data Science and machine learning field. I am searching for
the tutorials to learn:
printing... that I can learn the
topic "
printing press training course". Also tell
Adding JTable into existing Jframe.
Adding JTable into existing
Jframe. i need to add JTable into this code pls help me..
package Com;
import Com.Details;
import java.awt.Color...("serial")
public class AddPage extends
JFrame
{
JDesktopPane pane = new
Adding JTable into existing Jframe.
Adding JTable into existing
Jframe. i need to add JTable into this code pls help me..
package Com;
import Com.Details;
import java.awt.Color...("serial")
public class AddPage extends
JFrame
{
JDesktopPane pane = new
Adding JTable into existing Jframe.
Adding JTable into existing
Jframe. i need to add JTable into this code pls help me..
package Com;
import Com.Details;
import java.awt.Color...("serial")
public class AddPage extends
JFrame
{
JDesktopPane pane = new