printing data from JEditor Pane

I have a program in which the data is shown in JEditor Pane. I have used HTMl tags to get the deed format. Now i want to print it. how should i proceed :roll:

Posted On: Thursday 18th of October 2012 10:11:09 PM Total Views:  424
View Complete with Replies

Related Messages:

problem in printing swing components?   (541 Views)
i have a registration page, and after registration of a student i need to print the tc (transfer certificate), in the (Photo1430.jpg) image format, (in the same format shown in the image). field values are coming from the database.(ie. value of name, value of dob, value of place so on...) i am doing something like this: import java.awt.*; import java.awt.event.*; import java.awt.print.*; import javax.swing.*; public class PrintUIWindow implements Printable, ActionListener { JFrame frameToPrint; JLabel lblStuName, lblBirthPlace, lblDob, lblLastSch, lblLastExam, lblYearOdAdd,lblStudyingStandard; JLabel d, d1, d2, d3, d4; static JPanel panel; Box horiz1, horiz2, horiz3, horiz4, horiz5, horiz6; public PrintUIWindow() { panel = new JPanel(); lblStuName = new JLabel("1.) Name of Student (in Full)"); lblBirthPlace = new JLabel("2.) Place of Birth"); lblDob = new JLabel("3.) Date of Birth, Month and year (in figures)"); lblLastSch = new JLabel("4.) Last School College Attended"); lblLastExam = new JLabel("5.) Last Examination Passed"); d1 = new JLabel(" : ........................................................."); d2 = new JLabel(" : ........................................................."); d3 = new JLabel(" : ........................................................."); d4 = new JLabel(" : ........................................................."); d = new JLabel(" : ........................................................."); horiz1 = Box.createHorizontalBox(); horiz1.add(lblStuName); horiz1.add(d); horiz2 = Box.createHorizontalBox(); horiz2.add(lblBirthPlace); horiz2.add(d1); horiz3 = Box.createHorizontalBox(); horiz3.add(lblDob); horiz3.add(d2); horiz4 = Box.createHorizontalBox(); horiz4.add(lblLastSch); horiz4.add(d3); horiz5 = Box.createHorizontalBox(); horiz5.add(lblLastExam); horiz5.add(d4); Box vert = Box.createVerticalBox(); vert.add(Box.createVerticalStrut(100)); vert.add(horiz1); vert.add(Box.createVerticalStrut(30)); vert.add(horiz2); vert.add(Box.createVerticalStrut(30)); vert.add(horiz3); vert.add(Box.createVerticalStrut(30)); vert.add(horiz4); vert.add(Box.createVerticalStrut(30)); vert.add(horiz5); panel.add(vert); } public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page > 0) { /* We have only one page, and 'page' is zero-based */ return NO_SUCH_PAGE; } /* * User (0,0) is typically outside the imageable area, so we must translate * by the X and Y values in the PageFormat to avoid clipping */ Graphics2D g2d = (Graphics2D) g; g2d.translate(pf.getImageableX(), pf.getImageableY()); /* Now print the window and its visible contents */ frameToPrint.print(g); /* tell the caller that this page is part of the printed document */ return PAGE_EXISTS; } public void actionPerformed(ActionEvent e) { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) { try { job.print(); } catch (PrinterException ex) { /* The job did not successfully complete */ } } } public static void main(String args[]) { JFrame f = new JFrame("Print TC"); JButton printButton = new JButton("Print TC"); printButton.addActionListener(new PrintUIWindow()); panel.add("South", printButton); f.add(panel); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); } }
Java code printing junk characters in PDF   (463 Views)
I have a JAVA code that reads a PDF file from remote server. It then merges it with an existing PDF file and print the resultant. However, sometimes I observe that the PDF printed contains gibbersih data. It doesn't happen always. Is it some issue with the fonts used in PDF Or some inherent issue of Java, while printing PDF files. I use a print job object to print PDF file. Logic for printing the PDF file is as following private boolean printDocument(String fileName){ System.out.println("printComplianceDocument : Begin"); boolean result = false; PDDocument document = null; PDPage page = new PDPage(); try { document = PDDocument.load(fileName); PrinterJob pjob = PrinterJob.getPrinterJob(); PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet(); attr_set.add(Sides.DUPLEX); PrintService[] services = PrintServiceLookup.lookupPrintServices(null, attr_set); for(PrintService service : services){ if (service.getName().equalsIgnoreCase(SystemProp.getInstance().getWorkStation().getDfltRptPrinter().getAddress().trim())){ System.out.println("Printing Document to printer: " + service.getName()); pjob.setPrintService(service); pjob.setPageable(document); pjob.print(attr_set); result = true; break; } } //Try printing to Default Printer if appropriate Print Service is not found if(!result){ PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService(); System.out.println("Printing Document to Default Printer: " + defaultPrintService.getName()); pjob.setPrintService(defaultPrintService); pjob.setPageable(document); pjob.print(attr_set); result = true; } } catch (IOException e) { // Exception } catch (PrinterException e) { // Exception } System.out.println("printDocument : End"); return result; } Please share your ideas and suggest solutions if you could.
printing JTables - concatenating? what about the panels?   (655 Views)
I am printing a JTable in this manner: StringBuffer sb = new StringBuffer(); PrintRequestAttributeSet attribs = new HashPrintRequestAttributeSet(); attribs.add(new Copies(1)); attribs.add(OrientationRequested.PORTRAIT); int xx = 1; //left and right margin int yy = 1; //top and bottom margin. Note that bottom margin cannot be less than 15 mm int ww = 845; //Width int hh = 599; //Height int units = MediaPrintableArea.MM; attribs.add(new MediaPrintableArea(xx, yy, ww, hh, units)); String title = "My Table"; sb.append(title); MessageFormat footer = new MessageFormat("Page {0}"); getPayrollHeadcountList().getTable().setPreferredSize(new Dimension(500, 500)); getPayrollHeadcountTotalList().getTable().setPreferredSize(new Dimension(500, 100)); try { getPayrollHeadcountList().getTable().print(PrintMode.FIT_WIDTH, header, footer, true, attribs, false); //getPayrollHeadcountTotalList().getTable().print(PrintMode.FIT_WIDTH, header, footer, true, attribs, false); } catch (PrinterException pe) { Debug.trace(pe); }
Simple text printing with pagebreaks   (590 Views)
I have a report displayed in a GUI application as a simple text within JTextComponent. My goal is to print it but with page breaks at certain points. I have inserted \f at those places, however when I print page breaks are ignored and I get a weird character printed in those places where \f was and the rest of the text is just printed out without page breaks. One thing I v noticed is that if I output the report to a file and open it with MS Word page breaks are recognised and report is displayed correctly. However, if I try to open it with notepad page breaks are not recognised. I have tried converting the text to RTF but the \f character was still ignored. I would really appreciate if anyone shares their experience with something similar and how did you solve it cheers
printing a jtable   (580 Views)
I've got a swing JTable of about 20 rows ans 40 columns that I want to print on paper. I tried the table.print() method but that doesn't work, I just get one big empty cell on the paper. I tried an example from another site and that one works perfectly ( Does anyone know what's going wrong Is my table too large for the paper and do I need to resize it, and if so how
JTable printing problem   (630 Views)
I have sample of JTable with data that i would like to be right aligned, also orange background color cell renderer is applied, and font is set to be Tahoma BoldItalic with font size of 13. Problems that arise are, grid lines are over cell text, and also applied background color looks strange when PDF printer is used and document is zoomed. Interesting thing is that when font is set to be even grid lines doesn't intersect cell text. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.JTable.PrintMode; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; public class TablePrintTest extends JFrame { private static final long serialVersionUID = 1L; private static final Object[] COLUMN_NAMES = { "Column1", "Column2", "Column3" }; private static final Object[][] CELL_VALUES = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; private JButton printButton; private JTable table; public TablePrintTest() { super("TablePrintTest"); createGui(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void createGui() { table = new JTable(new DefaultTableModel() { private static final long serialVersionUID = 1L; @Override public Class getColumnClass(int columnIndex) { return Number.class; } @Override public int getColumnCount() { return COLUMN_NAMES.length; } @Override public int getRowCount() { return CELL_VALUES.length; } @Override public String getColumnName(int column) { return COLUMN_NAMES[column].toString(); } @Override public Object getValueAt(int row, int column) { return CELL_VALUES[row][column]; } }); table.setDefaultRenderer(Number.class, new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel label = (JLabel) super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); label.setHorizontalAlignment(SwingConstants.RIGHT); return label; } public java.awt.Color getBackground() { return; }; }); table.setFont(new Font("Tahoma", Font.ITALIC | Font.BOLD, 13)); printButton = new JButton("Print"); printButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Printable printable = table.getPrintable(PrintMode.NORMAL, null, null); PrinterJob pJob = PrinterJob.getPrinterJob(); pJob.setPrintable(printable); if (pJob.printDialog()) { try { pJob.print(); } catch (PrinterException e1) { e1.printStackTrace(); } } } }); JPanel contentPane = new JPanel(new BorderLayout()); contentPane.add(printButton, BorderLayout.NORTH); contentPane.add(new JScrollPane(table), BorderLayout.CENTER); setContentPane(contentPane); pack(); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new TablePrintTest().setVisible(true); } }); } }
Transfering data from the textbox in one class to a method in another class   (164 Views)
, I am having a problem, I want to transfer the data from a text field which is found in the class "ServerInterface" to a method in another class "Server". I wanted to transfer data to the method "sendData()" in the class Server when the user enter data in the textfield "txtSendMessage" and click on the button "btnSend" found in ServerInterface. I am new to Java and Socktet programming, the thing is that I have finally managed to understand socket programming after lots of hard work but my problem is that I am unable to merge my interface with the other class, could you please help me on this please. I am send the two class as attachment.
Dialog updates database - how to update other screens' combos/lists/tables?   (212 Views)
Hi , I have a dialog that modifies records within my database. But when I go to a different screen where the combo box has data from that table displayed it isn't updated with the new record that has been added. If I close my program and restart it then the combo box appears updated but I can't imagine many users wanting to do this on a regular basis. Is someone able to tell me how I can update the combo boxes/lists/tables on other screens that use this data Many
Problem in printing JTable values   (588 Views)
Dear Friends, I have to print the JTable values (on paper using print dialogue box). I'm using jtableObj.print to print the table values. But jtableObj.print takes more time to print the table values because it prints the values as a image(approximately 5 mins to print 10 pages). My code is , boolean complete = tableObj.print(mode, header, footer, showPrintDialog, null, interactive, null);
Passing data between JFrame & JDialog   (146 Views)
Here's the situation and what I've done so far - I have a JFrame in my program, which is instantiating a JDialog. Each of the two contain a JTextField. When I type in the JDialog's JTextField and press Enter, its text should be passed to JFrame's JTextField. I have tried to solve this in 2 ways. The code that I've written is as follows - //1) interface ICommunicator - interface ICommunicator { void setValue(String value); String getValue(); } //2) class ChildDialog - import javax.swing.*; import java.awt.*; import java.awt.event.*; class ChildDialog extends JDialog implements ICommunicator { JTextField jtf; String value = ""; public ChildDialog(JFrame parent) { super(parent); Container c = getContentPane(); c.setLayout(null); jtf = new JTextField(); jtf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("setting value: " + jtf.getText()); setValue(jtf.getText()); } }); jtf.setBounds(10, 10, 100, 25); c.add(jtf); setSize(300, 200); setLocation(350, 350); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setVisible(true); } public String getValue() { return value; } public void setValue(String value) { this.value = value; } } //3 class ParentDialog - import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ParentDialog extends JFrame { JTextField jtf; ChildDialog cd; public ParentDialog() { Container c = getContentPane(); c.setLayout(null); jtf = new JTextField(); jtf.setBounds(10, 10, 100, 25); c.add(jtf); setSize(500, 400); setLocation(250, 250); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); cd = new ChildDialog(this); /* Way No. 1 */ /* cd.jtf.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent ke) { if(ke.getKeyCode() == ke.VK_ENTER) { //jtf.setText(((ICommunicator) cd).getValue()); //Doesn't Work jtf.setText(cd.jtf.getText()); //Works } } }); */ /* Way No. 2 (Using an interface) */ /* String myValue = ((ICommunicator) cd).getValue(); while(true) { if(myValue.length()==0) { try { System.out.println("Sleeping"); Thread.sleep(1000); } catch(Exception e) { System.out.println("Exception " + e); } System.out.println("Getting The Value..."); myValue = ((ICommunicator) cd).getValue(); } else { break; } } jtf.setText(myValue); //Works */ } public static void main(String[] args) { new ParentDialog(); } }
passing data   (158 Views)
When you design a swing for UI, how do you usually pass the data what user has entered to the bussiness logic layer Can serialization or XML be used for the purpose If Yes, how hoping for the answer,
dynamic JComboBox with data from a database   (192 Views)
I am wondering if any one would have a idea to add items to checkbox from retrieved data from the database.I have been able to get the resultset displaying but cant seem to make the combobox more dynamic.
retrieve data in swing   (168 Views)
hi I want to retrieve data from database in java swing. how can do that I have 4 columns in java swing which would fetch values from database
how run tim data in jtable or show data in jtable from my database table   (308 Views)
i use DefaultTableModel. or swing jtable some body give me idea i use dumy class and use getColumnClass() and isCellEditable() class for modify the swing defult jtable or swing jtable give class because swing jtable give me defult data that read only but i want show data in jtable form my database table i change the title of table form give propery bu i have lot of row how i run time or dynamicly give data to jtable form my database table in jtable such as my table have data this type sname sno class address marks fahim 34 4 xxxx 545 aamir 43 4 ljfd 55 kashif 33 5 gd 444 and swing defult jtable give me this type data private String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"}; private Object[][] data = { {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)}, {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)}, {"Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false)}, {"Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true)}, {"Philip", "Milne", "Pool", new Integer(10), new Boolean(false)} }; or null data please give me ida how i show my database table data in jtable and how i set the jpanel location such as setlocation(12,14,3,5) but this code not give me right result please give right code
printing on A4 paper   (655 Views)
The paper object creates a letter sized piece of paper with one inch margins. Is there any way to set different margins to allow a page designed to fit on letter to also print on A4 by reducing the margins Or any other ideas ------------------
Inserting datas from JTable into csv file and vice versa.   (164 Views)
Can anyone please help me in getting values from a JTable in java swing into a csv file and also how to fill a JTable from the dats of a csv file. I am doing a project where i want this code plz anyone help me quick , it's urgent , i need detail code in java. I will be really thankful if anyone help in anyone.
data types not matching......   (122 Views) the given codes after compiling iam getting an error data types not matching..... please help me to correct it... import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.Button.*; public class List extends JFrame { public String s; JFrame f; JPanel po; JComboBox cb; JTextField tf; public static void main (String arg[]) { List obj = new List(); } public List() { f = new JFrame("list"); po= new JPanel(); tf= new JTextField(30); f.getContentPane().add(po); f.setVisible(true); f.setSize(300,300); String[] hos = {"Hostel1","Hostel2","Hostel3","hostel4","hostel6"}; cb = new JComboBox(hos); cb.setMaximumRowCount(3); //cb.addItemListener(this); po.add(cb); po.add(tf); process(); } public void process() { s= hos[cb.getSelectedItem()]; tf.setText(s); } } , A better option would be: public void process() { tf.setText((String)cb.getSelectedItem()); }
Using JTable to view a database table   (204 Views)
I am trying to write a Swing application that accesses a database via JDBC. I found the following expcerpt in the API docs for JTable: The "TableExample" directory in the demo area of the source distribution gives a number of complete examples of JTable usage, covering how the JTable can be used to provide an editable view of data taken from a database and how to modify the columns in the display to use specialized renderers and editors. What is the "source distribution" this mentions Is this a separate download from the J2SE JDK If it is included with the standard download, where would I find the "TableExample" directory I'm not currently at my development machine so it's difficult for me to look for it atm. If anyone can tell me where to find this example, that would be great! Layne
printing html and images using JEditorPane   (512 Views)
hi i am working on printing multiple html and images(png) in a single batch.. i am able to print all in a single batch if html files are single page files but if they are multipage files i am unable to print them. i am rendering html to a JEditorPane. i can print multiple multipage html files in a single batch but unable to do html files and images in a single batch .. anyone can help me thanx in advance -if you want i can provide code bye madhu
JTable Cell data validation/blank cell problem   (192 Views)
I am fairly new to Swings. I have a JTable that has to do some validations before its data is saved: (1) Each row of the Table allows values within a set range ex:0.5 to 100 (2) The cell may allow blank (later replaced before save with the lower range value) cell data will be Float data. My questions: (a) Right now I am iterating through JTable cells and checking each row-wise cell to see if they are within range. What is the correct way to do such validations (b) JTable by default is not allowing me to leave the cell blank (the focus remains on the cell if I try to leave it blank). How can I allow blank cell entries (c) If user enters an invalid data (say a String) in the cell that expects Float value, the text stays in the cell even though I clear the TableModel and repopulate the data. Any idea how to get over this [ October 07, 2004: Message edited by: Yash Sharma ]