printing html and images using JEditorPane


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
Posted On: Thursday 18th of October 2012 09:34:14 PM Total Views:  326
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




java web browser save all images on html for offline viewing

I recently started working on a simple server/client program where i send in a url and it returns that html file. i can them open that file in a simple web browser with thread by javanotes 6 sources. it then loads the images from the web to display them. i want to find out how it opens the html file and finds the image links and i would like to know how to save the images to be used later for offline viewing. webbrowserwiththread src import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import java.net.*; import java.io.*; /** * Defines a simple web browser that can load web pages from * URLs specified by the user in a "Location" box. Almost all * the functionality is provided automatically by the JEditorPane * class. The program loads web pages asynchronously in a * thread. See SimpleWebBrowser for a synchronous version. * This class can be run as a standalone application and has * a nested class that can be run as an applet. The applet * version can probably only read pages from the server from which * it was loaded. */ public class SimpleWebBrowserWithThread extends JPanel { /** * The main routine simply opens a window that shows a SimpleWebBrowserWithThread panel. */ public static void main(String[] args) { JFrame window = new JFrame("SimpleWebBrowserWithThread"); SimpleWebBrowserWithThread content = new SimpleWebBrowserWithThread(); window.setContentPane(content); window.setSize(600,500); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); window.setLocation( (screenSize.width - window.getWidth())/2, (screenSize.height - window.getHeight())/2 ); window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); window.setVisible(true); } /** * The public static class SimpleWebBrowserWithThread.Applet represents this program * as an applet. The applet's init() method simply sets the content * pane of the applet to be a SimpleWebBrowserWithThread. To use the applet on * a web page, use code="SimpleWebBrowserWithThread$Applet.class" as the name of * the class. A reasonable size for the applet is 600 by 480 or larger. */ public static class Applet extends JApplet { public void init() { SimpleWebBrowserWithThread content = new SimpleWebBrowserWithThread(); setContentPane( content ); } } /** * The pane in which documents are displayed. */ private JEditorPane editPane; /** * An input box where the user enters the URL of a document * to be loaded into the edit pane. A value URL string should * contain the substring "://". If the string in the box * does not contain this substring, then "http://" is * prepended to the string. */ private JTextField locationInput; /** * A button that the user can click in order to load the url * that is specified in the location input box. */ private JButton goButton; /** * Defines a listener that responds when the user clicks on * a link in the document. */ private class LinkListener implements HyperlinkListener { public void hyperlinkUpdate(HyperlinkEvent evt) { if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { new LoaderThread(evt.getURL()); } } } /** * Defines a listener that loads a new page when the user * clicks the "Go" button or presses return in the location * input box. */ private class GoListener implements ActionListener { public void actionPerformed(ActionEvent evt) { URL url; try { String location = locationInput.getText().trim(); if (location.length() == 0) throw new Exception(); if (! location.contains("://")) location = "http://" + location; url = new URL(location); } catch (Exception e) { JOptionPane.showMessageDialog(SimpleWebBrowserWithThread.this, "The Location input box does not\nccontain a legal URL."); return; } new LoaderThread(url); } } /** * Defines the thread that actually does the loading of a document. * The thread is also responsible for enabling/disabling the go button * and the location input box. */ private class LoaderThread extends Thread { private URL urlToLoad; LoaderThread(URL url) { // constructor starts the thread. urlToLoad = url; locationInput.setEnabled(false); goButton.setEnabled(false); start(); } public void run() { InputStream in = null; try { editPane.setContentType("text/plain"); editPane.setText("Loading URL " + urlToLoad + "..."); /* Open a URL connection just for the purpose of reading * the content type. I only want to show the document if * the content type is supported by JEditorPane. */ URLConnection connection = urlToLoad.openConnection(); in = connection.getInputStream(); String contentType = connection.getContentType(); if (contentType == null) throw new Exception("Can't determine content type of url."); if ( ! (contentType.startsWith("text/plain") || contentType.startsWith("text/html") || contentType.startsWith("text/rtf") ) ) throw new Exception("Can't display content type " + contentType); editPane.setText("Retrieving document contents..."); locationInput.setText(urlToLoad.toString()); in.close(); // I don't want to actually read from the connection! in = null; editPane.setPage(urlToLoad); } catch (Exception e) { editPane.setContentType("text/plain"); editPane.setText( "Sorry, the requested document was not found\n" +"or cannot be displayed.\n\nError:" + e); } finally { goButton.setEnabled(true); locationInput.setEnabled(true); locationInput.select(); locationInput.requestFocus(); if (in != null) { try { in.close(); } catch (Exception e) { } } } } } /** * Construct a panel that contains a JEditorPane in a JScrollPane, * with a tool bar that has a Location input box and a Go button. */ public SimpleWebBrowserWithThread() { setBackground(Color.BLACK); setLayout(new BorderLayout(1,1)); setBorder(BorderFactory.createLineBorder(Color.BLACK,1)); editPane = new JEditorPane(); editPane.setEditable(false); editPane.addHyperlinkListener(new LinkListener()); add(new JScrollPane(editPane),BorderLayout.CENTER); JToolBar toolbar = new JToolBar(); toolbar.setFloatable(false); add(toolbar,BorderLayout.NORTH); ActionListener goListener = new GoListener(); locationInput = new JTextField("math.hws.edu/javanotes/index.html", 40); locationInput.addActionListener(goListener); goButton = new JButton(" Go "); goButton.addActionListener(goListener); toolbar.add( new JLabel(" Location: ")); toolbar.add(locationInput); toolbar.addSeparator(new Dimension(5,0)); toolbar.add(goButton); } }
VIEWS ON THIS POST

141

Posted on:

Saturday 22nd September 2012
View Replies!

problem in printing swing components?

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); } }
VIEWS ON THIS POST

384

Posted on:

Tuesday 25th September 2012
View Replies!

All images are showing in Eclipse, only half when exported as Runnable Jar

Hi ! I have a very strange problem. And I can't figure out what could be the problem. I am developing my clone of the old game Frogger, I think that everybody knows the game I'm talking about. Well the main reason to develop Frogger is to learn about java games and 2D graphics, anyway this is my problem. When I run my Frogger application in Eclipse, all the images are shown with no problem with the appropriate animation (Logs moving in one direction car in another), then when I export this project as Runnable Jar and start it, I can see all images, except the car images. I know that the missing car images are moving because when I move my frog on the road it gets killed (returns to the start position.) This is my class that loads and holds the required images. the images are in the same folder (source) public class ImageLoader { private static ImageLoader instance; private Map imagesContext = new HashMap(); private Image image; private Toolkit toolkit; private ImageLoader(){ this.toolkit = Toolkit.getDefaultToolkit(); } public static ImageLoader getInstance(){ if(instance == null){ instance = new ImageLoader(); } return instance; } public Image loadImage(ImagesEnum image){ this.image = this.imagesContext.get(image); if(this.image == null){ this.image = this.toolkit.getImage(this.getImageURL(image)); this.imagesContext.put(image, this.image); } return this.image; } private URL getImageURL(ImagesEnum image){ return this.getClass().getResource("/source/" + ImagesEnum.getImageFilename(image)); } }
VIEWS ON THIS POST

136

Posted on:

Monday 1st October 2012
View Replies!

Displaying generated images greater than 32767 pixels on canvas

Hi I've been stuck on this for almost a week now so here it goes.. The general gist of the application is to generate one large horizontal bar up to approxiamtely 85,000 pixels to model the amount of seconds in a 24hr period, each pixel represents a second. This bar is split into multiple sections, these sections can number sometimes anywhere between 1000-2000, each represent a particular 'event' within the 24hr period. So I might have an event A coloured red and that is 300 seconds, another event Z may be 400 seconds with a yellow bar. So they've taken up 700 horizontal pixels so far --> 700 seconds within the 24hr timespan. These bars and their colours are generated according to a pre-determined 'model' so their never the same. Inititally I tried it with a ScrolledComposite to display the bar, it worked great up till 32767 pixels (the composite expanded to 32767 pixels) of which after I soon found out I reached the maximum pixel limit for composites in Windows and whatever that should have been drawn beyond this point has been cut off, the scrollbars also worked great displaying the 32767 pixels however and with no lag. So after having a consultation with the supervisor I've decided to go for the Canvas approach. The thing is my original approach was with a Canvas but I got stuck hence making me switch to a ScrolledComposite. Now I am back to square one. Here are my questions: 1) Would this be the best approach in your opinion Does canvas support a pixel width of 85,000 (I tried with 'Image' and it failed) My idea was to have a 1000 pixel wide fixed width canvas with scrollbars. Everytime the scrollbars or a 'forward button' is pressed the canvas is repainted to simulate a side "scroll" to show the next lot of pixel graphics. Once the button is clicked on again it shows the next lot of pixel graphics. With this approach I only ever have to deal with 1000 pixels at a time and not the whole 85,000 pixels however I will still be able to view the whole 85,000 pixels without lag or reaching a limit. How would I 'technically' be able to go around doing this Some pointers please! 2) I wrote a "Canvas Test" program to try to test out my idea mentioned above. package canvas; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Event; public class Test { // Test if scrollbars should be added for the canvas or the shell - whichever works better. static int shellStyle = SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND | SWT.CLOSE | SWT.MIN | SWT.RESIZE | SWT.MAX | SWT.H_SCROLL; static int canvasStyle = SWT.NO_REDRAW_RESIZE;// | SWT.H_SCROLL | SWT.V_SCROLL; public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display, shellStyle); shell.setLayout(new FillLayout()); shell.setBackground(display.getSystemColor((SWT.COLOR_CYAN))); shell.setText("Canvas Test"); /** * SWT.NO_BACKGROUND style bit prevents the background of the program to be filled before * the painting of the canvas in the program. * SWT.NO_REDRAW_RESIZE ensures that only the damaged areas of the canvas are repainted when * it is resized as opposed to repainting the whole area. */ final Canvas canvas = new Canvas(shell, canvasStyle); canvas.setLayout(new FillLayout()); canvas.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); final Point origin = new Point(0,0); final ScrollBar hBar = shell.getHorizontalBar(); Rectangle size = canvas.getBounds(); hBar.setMaximum(size.width); hBar.setMinimum(0); // hBar.addListener(SWT.Selection, scrollListener); // vBar.addListener(SWT.Selection, scrollListener); // Create a paint handler for the canvas canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { // Do some drawing e.gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_YELLOW)); e.gc.fillRectangle(100, 200, 100, 200); e.gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN)); e.gc.fillRectangle(900, 200, 600, 200); e.gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_MAGENTA)); e.gc.fillRectangle(500, 200, 300, 200); e.gc.setBackground(display.getSystemColor(SWT.COLOR_GRAY)); e.gc.fillRectangle(1600, 200, 300, 200); } }); // The below event handlers allow for horizontal scrolling functionality hBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { int hSelection = hBar.getSelection(); // Get the current position of the ScrollBar int destX = -hSelection - origin.x; // Store the new position after scrolling Rectangle rect = shell.getBounds(); canvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); origin.x = -hSelection; } }); shell.addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { Rectangle rect = canvas.getBounds(); Rectangle client = shell.getClientArea(); hBar.setMaximum(rect.width); hBar.setThumb(Math.min(rect.width, client.width)); int hPage = rect.width - client.width; int hSelection = hBar.getSelection(); if (hSelection >= hPage) { if (hPage
VIEWS ON THIS POST

99

Posted on:

Monday 1st October 2012
View Replies!

Java code printing junk characters in PDF

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.
VIEWS ON THIS POST

282

Posted on:

Monday 1st October 2012
View Replies!

Print Multi page JEditorPane html contents in Java

down vote favorite share [fb] share [tw] I have developed a code in Java where I have embedded HTML content into a JEditorPane by setting its content type to text / html. However this content spills over to the second page and so on. I know that the JEditorPane has a print() method that prints the contents of the JEditorPane and I know that the print() method of the JEditorPane prints all the contents of the JEditorPane and even prints multiple pages. What I want is that the top, left, right and bottom margins should be set to 0. If I would simply leave the work of setting the margins to 0 at run-time by changing the print settings before printing, it would just not work. Due to this I had to implement the Printable interface. But when I used the Printable interface it allows to print only the first page of the JEditorPane. When I searched a lot for this solution I got this link on Google; http://download.oracle.com/javase/tutorial/displayCode.htmlcode=http://download.oracle.com/javase/tutorial/2d/printing/examples/PaginationExample.java But the problem here is that I am using html contents in the JEditorPane. I dont know how to integrate the above solution provided in the link with a JEditorPane that consists of HTML Code
VIEWS ON THIS POST

144

Posted on:

Wednesday 17th October 2012
View Replies!

Error on seting images to labels: NullPointException

Please have a look at the following code Class mainWindow import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class mainWindow extends JFrame implements ActionListener { JButton open, preview; JFileChooser fileChooser; File selectedFiles[]; String str[]; JLabel label; preview p; int miliSeconds = 1000; public mainWindow() { open = new JButton("Open"); open.addActionListener(this); preview = new JButton("Preview"); preview.addActionListener(this); label = new JLabel(); fileChooser = new JFileChooser(); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); panel.add(open); panel.add(preview); JPanel labelPanel = new JPanel(); labelPanel.setLayout(new FlowLayout()); labelPanel.add(label); JPanel main = (JPanel)getContentPane(); main.setLayout(new BorderLayout()); main.add(panel,"Center"); main.add(labelPanel,"South"); } public void actionPerformed(ActionEvent ae) { if(ae.getSource().equals(open)) { fileChooser.setMultiSelectionEnabled(true); int returnVal = fileChooser.showOpenDialog(mainWindow.this); if(returnVal==JFileChooser.APPROVE_OPTION) { selectedFiles = fileChooser.getSelectedFiles(); str = new String[selectedFiles.length]; for(int i=0;i
VIEWS ON THIS POST

130

Posted on:

Wednesday 17th October 2012
View Replies!

printing JTables - concatenating? what about the panels?

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); }
VIEWS ON THIS POST

466

Posted on:

Wednesday 17th October 2012
View Replies!

Simple text printing with pagebreaks

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
VIEWS ON THIS POST

395

Posted on:

Wednesday 17th October 2012
View Replies!

How to display 256 images in a 16x16 grid

My target is to display 256 images in a 16x16 grid (as the subject of this topic already hints at). This grid should be positioned in a container. When clicking with the mouse on one of the images I want to know on which image the click was made, and that in a way that makes it easy to get the coordinates (0,0 being the top left image, 15,15 the bottom right). I use NetBeans and JSE 6. As a beginner I would like to get a hint to the following preliminary thoughts I had. a. Use labels (JLabel). Problem: You have to generate 256 of them. Not very attractive to do with NetBeans - and you have no elegant way to get the coordinates back (using the name of JLabel - JLabel3x5, JLabel15x15 - seems very awkward , using the graphic coordinates is not reliable if the window is resized). Even if you do not use NetBeans and generate the labels manually, say in an array, the coordinate problem remains. b. Use a table (JTable), display the images in a grid and prevent the cells from being editable. As far as I got it you can define your own TableModel and include something like public boolean isCellEditable(int row, int col) { return false; }
VIEWS ON THIS POST

101

Posted on:

Wednesday 17th October 2012
View Replies!

images in JList

, I made an applet and added a JList object into it and I have a folder containing images (0.jpg, 1.jpg, 2.jpg) I want to add these images in the JList object in the form of loop when I tries this BufferedImage[] images; private void loadImages() { String picFolder = System.getProperty("user.home") + System.getProperty("file.separator") + "/"; File file = new File(picFolder); String[] fileNames = new String[getFilesCount(file)]; images = new BufferedImage[fileNames.length]; for (int i = 0; i < images.length; i++) { try { String path = picFolder + i + ".jpg"; System.out.println(path); images[i] = ImageIO.read(new File(path)); } catch (MalformedURLException mue) { System.out.println("url: " + mue.getMessage()); } catch (IOException ioe) { System.out.println("read: " + ioe.getMessage()); } } ImagesList.setListData(images); }
VIEWS ON THIS POST

106

Posted on:

Wednesday 17th October 2012
View Replies!

printing a jtable

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 (http://java.sun.com/docs/books/tutorial/uiswing/misc/printtable.html). 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
VIEWS ON THIS POST

388

Posted on:

Wednesday 17th October 2012
View Replies!

JTable printing problem

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 Color.orange; }; }); 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); } }); } }
VIEWS ON THIS POST

438

Posted on:

Wednesday 17th October 2012
View Replies!

Problem in printing JTable values

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);
VIEWS ON THIS POST

387

Posted on:

Wednesday 17th October 2012
View Replies!

insert images in JFrame

Kindly any body guide me who to insert images in JFrame [Edit to give meaningful topic] [ August 10, 2007: Message edited by: David O'Meara ]
VIEWS ON THIS POST

99

Posted on:

Wednesday 17th October 2012
View Replies!

Resolution Problem for Background images

1)I have one swing based gui application, i am facing some resolution problem in it. for the time being what i want to do is ... Suppose my application is runnig and user minimizes the window and change the resolution say from 800X600 to 1024X768, i would like to run some code basically i would like to change the background image of my application which is there in layered pane wright now. 2)Also i would like to have some code for stretching the images (background)if user resizes his main application window. and the image format which will be resolution independent (or size independent). basically it should not get disturbed when it's size gets chaged according to the size of the window.
VIEWS ON THIS POST

68

Posted on:

Thursday 18th October 2012
View Replies!

printing on A4 paper

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 ------------------
VIEWS ON THIS POST

490

Posted on:

Thursday 18th October 2012
View Replies!

Jpeg images not proper in MAC

hi i am saving a component to a jpeg image(converting component to buffered image) with the code line ImageIO.write( image, "jpg", file ); this code works fine when component is saved in windows but in case of Mac OS X the image created gets a reddish tint . Can anyone tell me where the problem is or is there something else i should do while saving to jpeg images in mac ps: i tried with following code too but same result JPEGImageEncoder jpgencoder = JPEGCodec.createJPEGEncoder(out); jpgencoder.encode(image);
VIEWS ON THIS POST

150

Posted on:

Thursday 18th October 2012
View Replies!

Problem in displaying images while resizing in AWT

With 500X500 screen size the images are displayed properly. If I change the screen size 350X450 none of the images are getting displayed. However if I maximize the screen and resize window size back the images are visible. We cannot go for swings because the JVM for PDA supports AWT only. Please give your valuble inputs on this.
VIEWS ON THIS POST

124

Posted on:

Thursday 18th October 2012
View Replies!

Loading html page in swing

I want to load html page which contains javascript code like :- function fun() { window.open('directoryname/filename.htm', 'title', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes ,height=500,width=700') } I am using JEditor to show html pages i.e. JEditor.setPage(url) method to show url . But it is not understanding javascript code. Is there any solution to make JEditor script enabled second solution is to load default browser .If I load default browser ,it is showing browser correctly.But I don't want to show any menu-bar or toolbar.Is there any solution to hide menubar & toolbars of browser at run-time. Or if there is another solution to show html pages [containning scripts] .Please tell me.
VIEWS ON THIS POST

111

Posted on:

Thursday 18th October 2012
View Replies!