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); }

Posted On: Wednesday 17th of October 2012 05:53:22 AM Total Views:  655
View Complete with Replies

Related Messages:

Confusion about this reference to a JFrame   (204 Views)
import java.awt.*; import javax.swing.*; public class SimpleScreenManager{ private GraphicsDevice device; SimpleScreenManager(){ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); device = ge.getDefaultScreenDevice(); } public void setFullScreen(DisplayMode displayMode, JFrame window){ window.setUndecorated(true); window.setResizable(false); device.setFullScreenWindow(window); //test if displayMode has parameters passed to it and change mode is supported if(displayMode != null && device.isDisplayChangeSupported()){ try{ device.setDisplayMode(displayMode); } catch (IllegalArgumentException ex){ //ignore illegal mode for this device } } } public Window getFullScreenWindow (){ return device.getFullScreenWindow(); } public void restoreScreen(){ Window window = device.getFullScreenWindow(); if(window!=null){ window.dispose(); } device.setFullScreenWindow(null); } } import java.awt.*; import javax.swing.*; public class FullScreenTest extends JFrame{ public static void main(String [] args){ DisplayMode displayMode; //Checking if args were passed via the command line ie java FullScreenTest 800,600,32 if(args.length == 3){ displayMode = new DisplayMode( Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), DisplayMode.REFRESH_RATE_UNKNOWN); } //setting default display settings if no args were used else { displayMode = new DisplayMode(800,600,32, DisplayMode.REFRESH_RATE_UNKNOWN); } FullScreenTest test = new FullScreenTest();; } private static final long Demo_Time = 5000; public void run(DisplayMode displayMode){ setBackground(; setForeground(Color.white); setFont(new Font("Dialog", Font.PLAIN, 24)); SimpleScreenManager screen = new SimpleScreenManager(); try { screen.setFullScreen(displayMode, this); try { Thread.sleep(Demo_Time); } catch (InterruptedException ex){} } finally { screen.restoreScreen(); } } public void paint(Graphics g){ g.drawString(" World",20,50); } }
Question about drop down lists from JComboBox within an applet   (269 Views)
When I click on the down arrow of a standard JComboBox in an applet and the list of strings are displayed, if I then drag the browser window, the drop down list stays in the same place instead of either being closed or moving with the browser window. I started noticing this when I started using Java 7, but I think this also occurs with Java 6 and 5. When run within the applet viewer in Eclipse, moving the applet window there closes the drop-down during the process of moving the window. Anybody else noticing this If so are any suggestions for a possible solution. Ideally I'd want the list to move with the browser window without the drop-down closing. My example code that demonstrates the problem is as follows: import javax.swing.JApplet; import javax.swing.JComboBox; public class ComboApplet extends JApplet { public void init () { String [] testStrings = new String [] {"This", "is", "a", "test"}; JComboBox comboBox = new JComboBox(testStrings); add(comboBox); } }
easiest way to create & setting jpanels?   (286 Views)
I am try to creating 21 jpanels with different ways... 1. drag & drop from eclipse windowsbuilder 21 times so each time its code like with settings also JPanel panel_example = new JPanel(); panel_example.setBackground(new Color(245, 245, 245)); panel_example.setFont(new Font("Trebuchet MS", Font.PLAIN, 12)); panel_example.setBorder(new LineBorder(new Color(0, 0, 0), 1, true)); panel_example.setBounds(78, 68, 86, 82); panel_example.setLayout(new BorderLayout(0, 0));
Question about programming style   (285 Views)
When creating a gui application or an applet, is there a standard about the best way to set up the code For example, is it better to layout the code like this public void init() { setLayout(null); output = new JTextField("This is a textfield", 100); output.setBounds(0, 0, 100, 50); add(output); one = new JButton("1"); one.setBounds(5, 40, 50, 50); add(one); two = new JButton("2"); two.setBounds(65, 40, 50, 50); add(two); }
Question about Color and BufferedImage   (215 Views)
Hi , I'm trying to learn more about java computer graphics, and in my study I encountered following problem. Probably there is a simple solution to this, but I'm baffled. Here's the question, why the integers that represent color are not the same Also I noticed that when I change value 255 => 254 the integer of the color object gets recalculated but the one in the bufferedImage doesn't, why is that public static void main(String[] args) { Color c = new Color(255, 110, 75, 100); BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); Graphics g = image.getGraphics(); g.setColor(c); g.fillRect(0, 0, 100, 100); System.out.println(c.getRGB()); System.out.println(image.getRGB(40, 40)); } Console: 1694461515 1694461514
overlapping problem of jpanels   (349 Views)
As i got reply from Wendy Gibbons in JDBC section's topic which i created worry about other considerations when you have the simplest version working. Here i try simplest version as per my thought. I make simple swing program (Just swing no jdbc or hibernate & db), Name Contains 1 JFrame, Array of jpanels.(only 3 jpanels i create by array). Major code is here., but i modified it as i try in 2-3 days after last post in that question. If you want to see how it developed, 1. 3 questions regarding JPanel. Creation of problem:- When program runs 3 panels we can see, 0,1,2. If we drag & drop panel 0 on panel 2, it will locate beside it because code goes to check_overlap_panel(); & run for loop & check if condition & set as below. simpledm.comp_panel.setLocation(simpledm.comp_panel.getX()+25, simpledm.comp_panel.getY()+25); but when we drag & drop panel 1 on panel 2,it will do same for checking ovelaping against panel 2, & setlocation as per above quote,but it forget already that location occupy by panel 0. Problem panel 1 not try to cross check overlap against panel 0. If i increase myindex = any number, then it should be try to setlocation of panel as avoid overlap against another panel. I try my best & then post question...I also try sscce for code What i do:- Here i try to create 13 boolean flags to check many if-else conditions & for easiness i create 5 functions Conditions like 1. In check_resolutionboundries() function i check panel should not move beyond systems resolution, so if program run on any monitor which has any resolution, then it will run without trouble. This function i called in mousedragged event. 2. When program runs all integers are 0 so 1st condition is check integer against 0 in function check_int_zero(). 3. When function check_int_zero() calls in chek_flags(), to check probability of flags true & false. 4. check_overlap_panel() function contain code for checking panels overlap or not. private void check_overlap_panel() { for (Counter= 0; Counter < panels.length; Counter++) { if (simpledm.comp_panel.getBounds().intersects(simpleExample.panels[Counter].getBounds())) { if (Integer.parseInt(simpledm.comp_panel.getName()) != Integer.parseInt(panels[Counter].getName())) { Flag_over= false; }else { Flag_over = true; }}}}
Array of jpanels within JScrollPane   (291 Views)
I try to create Array of jpanels within JScrollPane... I partially done same but instead of JScrollPane i created can see code here. Here i write simple code for JScrollPane import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.GraphicsEnvironment; import java.awt.Image; import java.awt.Point; import java.awt.Rectangle; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; public class scp { static int Array_counter = 11; static int counter,j,k = 0; static JPanel[] panels = new JPanel[Array_counter]; static JLabel[] labels = new JLabel[Array_counter]; JFrame myframe = new JFrame(); sp bgp = new sp(); int sys_want_w, sys_want_h; Point locations; Point locations1; public void mygui() { GraphicsEnvironment env = GraphicsEnvironment .getLocalGraphicsEnvironment(); System.out.println(env.getMaximumWindowBounds()); sys_want_w = env.getMaximumWindowBounds().width; sys_want_h = env.getMaximumWindowBounds().height; JScrollPane myjScrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); myjScrollPane.setViewportBorder(BorderFactory.createLineBorder(, 1)); myframe.setSize(800, 600); myframe.setLocationRelativeTo(null); myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myframe.setVisible(true); myframe.setResizable(true); bgp.setLayout(null); bgp.setSize(new Dimension(364, 96)); bgp.setOpaque(true); bgp.setBorder(BorderFactory.createLineBorder(, 1)); Rectangle r1 = new Rectangle(myjScrollPane.getX(), myjScrollPane.getY(),myjScrollPane.getWidth(), myjScrollPane.getHeight()); bgp.setBounds(r1); myjScrollPane.add(bgp); myjScrollPane.computeVisibleRect(r1); myjScrollPane.setBounds(myframe.getX(),myframe.getY(),myframe.getWidth(),myframe.getHeight()); myjScrollPane.setViewportView(bgp); myjScrollPane.computeVisibleRect(bgp.getBounds()); myframe.getContentPane().add(myjScrollPane); for (counter = 0; counter < panels.length; counter++) { panels[counter] = new JPanel(); panels[counter].setLayout(new FlowLayout()); panels[counter].setBackground(new Color(255, 255, 204)); panels[counter].setSize(25, 25); panels[counter].setBorder(BorderFactory.createLineBorder(,1)); panels[counter].setName(String.valueOf(counter)); labels[counter] = new JLabel(); labels[counter].setText(String.valueOf(counter)); panels[counter].add(labels[counter], null); panels[counter].setOpaque(true); Point locations = new Point((0 + (26 * k)), ((j))); k++; panels[counter].setLocation(locations); bgp.add(panels[counter]); } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new scp().mygui(); } }); } class sp extends JPanel { private static final long serialVersionUID = 1L; Image image; public sp() { try { image ="bg.jpg"), "bg.jpg")); } catch (Exception e) { /* handled in paintComponent() */ } } @Override protected void paintComponent(Graphics gr) { super.paintComponent(gr); if (image != null) gr.drawImage(image, 0, 0, sys_want_w - 8, sys_want_h - 35, this); } } }
how to calculate cpu/memory utilizing by jcomponents/jpanels/Jframe?   (306 Views)
I create 1 Jframe in that 1 big jpanel fitted to that JFrame. In that jpanel i create array of jpanels(small) say n numbers...n=5,6,7,,9...up to...99. size (25,25) Now i want print statement which shows cpu/memory utilized by each panel/component...
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); } }
gridlayout not working with custom jpanel and jscrollpane; my jpanels get cut off   (341 Views)
I'm trying to add my own implementation of jpanel to another jpanel, in a scrollpane, so that as it adds more it will make a list of them down the screen. Unfortunately I can't seem to put space between my jpanels; when I set the second two gridlayout parameters, parts of them get cut off (so that they appear shorter vertically). Any idea why this is happening or how to get around it (called from a method in a jframe class) miniPanel = new JPanel(); miniPanel.setLayout(new java.awt.GridLayout(100, 4,0,60)); for(int i=0;i
Doubt about layouts.. (its simple I think)   (228 Views)
My doubt is simple, I dont want to use AbsoluteLayout. So, I putted a Panel inside a frame on the West position using BordeLayout (default). Then I set the frame layout to BoxLayout (YAXIS). So I putted a JLabel and a JTextBox. I wanted it: Nome: [___________________________________] But the JTextBox extended until the border of the panel. How do I fix it
Advice about Eclipse Window Builder config   (270 Views)
Hi Im creating a big project and I want to listen your opnion about the automatic event handler generation. See the screen below: ` As you can see Im using anonymous classes for event handling. Its the best way for big projects or you don't think so I really like that all the things clear and for big projects I don't know if this is the best configuration.
Question about GUI (with NetBeans IDE)   (260 Views)
. I want to ask about my vision for the GUI. I'm using NetBeans IDE to make it. My idea is something like this, we have a few JPanels with JLabels, and JButtons. First JPanel it's a menu and it is only visible JPanel at the application starts. When we click on the one of the buttons (let's say "Information") we change Menu JPanel Visibility to false, and the JPanel which include the "Information" is now Visible. The JPanel "Information" also has got JLabels and JButtons, and one of JButtons is a "Main Menu" which (when clicked) sets the Menu JPanel visibility as true, and set Information JPanel visibility as false. My second idea (which is just stupid ;>) is to remove all components on JButton click, and create new components. So in Menu JPanel we got JButton information. When we click it, we remove all components that are in Menu JPanel, and we create new components, that are needed in Information JPanel. I think that both ideas are terrible, but I have no other idea how to make it. I was thinking about web app, but I don't have such knowledge to create it.
Swing, awareness about unsaved data   (285 Views)
I am working on a Swing application for data maintenance (Java 6). There is a JFrame with several JTextFields. If the user is editing a record, there is UNSAVED data until she/he presses the Save-Button. The application should always be aware if there is unsaved data. How can this be done Best regards Gerald
Anybody can tell me some websites about investigating the Swing or other UI deeply?   (320 Views)
Can anybody tell me some websites about investigating the Swing or other UI deeply Thank you,everybody in advance.
Question about "Java Icons"   (172 Views)
I am creating an application, in this application, I need to use Icons like "copy", "paste", "cut" etc. Rather than using images of my own as Icons, I know there are some "Built In Icons' in Java. Anyway, According to my requirement, there should be at least two type of the same icon, for an example, "Copy Icon NORMAL" and "Copy icon MouseHover". Is there is any kind of FREE package which provide these Icons Apart from that, this is the first time I am gonna use these BUILT IN ICONS, so please tell me how to use these too.
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.
Want to know about border Layout and gridbag layout   (230 Views)
I need help on java swing layouts............. Please help asap.