Again jtable printing

how can i print a header for a jtable besides the column name. example i want a string of data before printing the table.thanks...

On the printout only one line appears, the \n is
ignored. Is there a possibility to have multiline
footers with Java5 table printing?From my experience no. You may have to roll out your own printing
code
Don't mind if i ask but why do you want a multiline footer?
Richard West

Similar Messages

  • JTable Print to Adobe Acrobat Error

    I'm having trouble printing a jTable using Java 1.5.0_03 to Adobe Acrobat (6.0). Whenever I call print using (assuming proper try/catch statements) either
    jTable.print();or
    printJob.setPrintable(jTable.getPrintable(JTable.PrintMode.FIT_WIDTH, new MessageFormat("Header"), new MessageFormat("Footer")));
    if (printJob.printDialog())
    printJob.print();the printed jTable's column headers extend higher than they are supposed to like they were stretched (like when you drag the scroll bar down on your screen and the screen freezes), and effectively cover up parts of the header (the "Header" in this case).
    My jTable is setup as follows
    XYZ = new DefaultTableModel();
    XYZ.addColumn("A");
    XYZ.addColumn("B");
    jTable = new JTable();
    jTable.setModel(XYZ);I think this is an error with how the print function interacts with Adobe Acrobat as I don't have this problem printing to a normal printer. Is there any way to fix this?

    Are you saying there is no Adobe PDF printer, or it does not work? If it simply that it does not seem to work, then try to print to file with the printer. Then open the file in Distiller. If you get a resultant PDF, then the problem is most likely that you have somehow deactivated AcroTray.exe in the running applications. The program is in the Acrobat folder and needs to be started in that case. It should also be listed in your boot sequence for startup.

  • JTable printing and multiline footer

    I am trying to switch to Java5 JTable printing. I had a 2 lines footer text on the printout before. With Java5 I tried it this way
                    Printable printable = thistable.getPrintable
                        JTable.PrintMode.FIT_WIDTH,
                        new MessageFormat("title"),
                        new MessageFormat("line1" + "\n" + "line2")
                    );  On the printout only one line appears, the \n is ignored. Is there a possibility to have multiline footers with Java5 table printing?

    On the printout only one line appears, the \n is
    ignored. Is there a possibility to have multiline
    footers with Java5 table printing?From my experience no. You may have to roll out your own printing
    code
    Don't mind if i ask but why do you want a multiline footer?
    Richard West

  • JTable printing problem

    Hi , I have a problem add printing routine for printing to this code.
    Sombody help me.
    I no post all code but my prube no functioned.
    thanks you
    code :
    package com.froses.tablemodels;
    * SimpleDBTable.java
    * A demonstration of using ODBC to read data from an Access database
    * and display the values in a JTable.
    * This file requires that the new.mdb file exists and has been mapped
    * using ODBC to a datastore named 'newdb' with blank username and password.
    * Gordon Branson January 2004
    import javax.swing.*;
    import java.awt.Dimension;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    public class SimpleDBTable extends JPanel {
    private boolean DEBUG = true;
    private int rows = 10, cols = 5;
    private String url = "jdbc:odbc:Sego";
    private Connection con;
    private Statement stmt;
    private JButton btnRead, btnDelete, btnWrite, btnClose;
              /* Setup the table column names */
    private String[] columnNames = {"Medico",
    "Descripci�n",
    "Obra social",
    "Items",
    "Codigo"};
              /* declare an Object array large enough to hold the database table */
    private Object[][] data = new Object[rows][cols];
    private JTable table;
    public SimpleDBTable() {
    super(new BorderLayout());
    /* Load ODBC diver */
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    } catch(java.lang.ClassNotFoundException e) {
    System.err.print("ClassNotFoundException: ");
    System.err.println(e.getMessage());
              /* create the JTable */
    table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(500, 300));
    /* Now read from the database */
    populateTable();
    if (DEBUG) {
    table.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    printDebugData();
    //Create the Title Label.
    JLabel title = new JLabel("Database Access in Java");
    title.setFont(new java.awt.Font("Arial", 1, 24));
    title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    //Add the label to this panel.
    add("North",title);
    //Create the scroll pane and add the JTable to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this panel.
    add("Center",scrollPane);
    // Create a button panel with a default layout
    JPanel buttons = new JPanel();
    // Create the buttons
    btnRead = new JButton("Read");
    btnClose = new JButton("Close");
    btnWrite = new JButton("Write");
    btnDelete = new JButton("Delete");
    // Add action listeners
    btnRead.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    populateTable();
    btnDelete.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    deleteTable();
    btnWrite.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    writeTable();
    btnClose.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    System.exit(0);
    // Add the buttons to the button panel
    buttons.add(btnRead);
    buttons.add(btnWrite);
    buttons.add(btnDelete);
    buttons.add(btnClose);
    // Add the buttons panel to main panel
    add("South",buttons);
    private void populateTable(){
         /* Define the SQL Query to get all data from the database table */
    String query = "SELECT * FROM Datos";
    /* First clear the JTable */
    clearTable();
    /* get a handle for the JTable */
    javax.swing.table.TableModel model = table.getModel();
    int r = 0;
    try {
    /* connect to the database */
    con = DriverManager.getConnection(url, "", "");
    stmt = con.createStatement();
    /* run the Query getting the results into rs */
                   ResultSet rs = stmt.executeQuery(query);
                   while ((rs.next()) && (r<rows)) {
                        /* for each row get the fields
                        note the use of Object - necessary
                        to put the values into the JTable */
                   Object nm = rs.getObject("Medico_solic");
                   Object sup = rs.getObject("Descip_Item");
                   Object pri = rs.getObject("Obra_Social");
                   Object sal = rs.getObject("M�dico_opera");
                   Object tot = rs.getObject("Codigo_estudio");
                   model.setValueAt(nm, r, 0);
                   model.setValueAt(sup, r, 1);
                   model.setValueAt(pri, r, 2);
                   model.setValueAt(sal, r, 3);
                   model.setValueAt(tot, r, 4);
                   r++;
    stmt.close();
    con.close();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    private void deleteTable(){
         emptyTable();
         clearTable();
    private void emptyTable(){
         /* Define the SQL Query to get all data from the database table */
    String query = "DELETE * FROM COFFEES";
    try {
    /* connect to the database */
    con = DriverManager.getConnection(url, "", "");
    stmt = con.createStatement();
    /* run the Query */
                   stmt.executeUpdate(query);
    stmt.close();
    con.close();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    /* private void writeTable(){
         /* First clear the table */
    /*      emptyTable();
         PreparedStatement insertRow;// = con.prepareStatement(
         String insertString = "INSERT INTO COFFEES " +
                                  "VALUES (?, ?, ?, ?, ?)";
    int numRows = table.getRowCount();
    javax.swing.table.TableModel model = table.getModel();
    Integer sup, sal, tot;
    Double pri;
    Object o;
    if(DEBUG) System.out.println("\nDoing Write...");
    try {
    /* connect to the database */
    /* con = DriverManager.getConnection(url, "", "");
    insertRow = con.prepareStatement(insertString);
         for (int r=0; r < numRows; r++) {
              if (model.getValueAt(r, 0) != null){
                   insertRow.setString(1, (String) model.getValueAt(r, 0));
                   //o = model.getValueAt(r, 1);
                   if(DEBUG) System.out.println(model.getValueAt(r, 1).toString());
                   sup = new Integer((String) model.getValueAt(r, 1));
                   insertRow.setInt(2, sup.intValue());
                   pri = new Double((String) model.getValueAt(r, 2));
                   insertRow.setDouble(3, pri.doubleValue());
                   sal = new Integer((String) model.getValueAt(r, 3));
                   insertRow.setInt(4, sal.intValue());
                   tot = new Integer((String) model.getValueAt(r, 4));
                   insertRow.setInt(5, tot.intValue());
                   insertRow.executeUpdate();
                   System.out.println("Writing Row " + r);
    insertRow.close();
    con.close();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    clearTable();
    private void writeTable(){
         /* First clear the table */
         emptyTable();
         Statement insertRow;// = con.prepareStatement(
         String baseString = "INSERT INTO Datos " +
                                  "VALUES ('";
         String insertString;
    int numRows = table.getRowCount();
    javax.swing.table.TableModel model = table.getModel();
    Integer sup, sal, tot;
    Double pri;
    Object o;
    if(DEBUG) System.out.println("\nDoing Write...");
    try {
    /* connect to the database */
    con = DriverManager.getConnection(url, "", "");
         for (int r=0; r < numRows; r++) {
              if (model.getValueAt(r, 0) != null){
                   insertString = baseString + model.getValueAt(r, 0)+"',";
                   insertString = insertString + model.getValueAt(r, 1)+",";
                   insertString = insertString + model.getValueAt(r, 2)+",";
                   insertString = insertString + model.getValueAt(r, 3)+",";
                   insertString = insertString + model.getValueAt(r, 4)+");";
                   if(DEBUG) System.out.println(insertString);
              insertRow = con.createStatement();
                   insertRow.executeUpdate(insertString);
                   System.out.println("Writing Row " + r);
    insertRow.close();
    con.close();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    clearTable();
    private void clearTable(){
    int numRows = table.getRowCount();
    int numCols = table.getColumnCount();
    javax.swing.table.TableModel model = table.getModel();
    for (int i=0; i < numRows; i++) {
    for (int j=0; j < numCols; j++) {
    model.setValueAt(null, i, j);
    private void printDebugData() {
    int numRows = table.getRowCount();
    int numCols = table.getColumnCount();
    javax.swing.table.TableModel model = table.getModel();
    System.out.println("Value of data: ");
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + model.getValueAt(i, j));
    System.out.println();
    System.out.println("--------------------------");
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("SimpleDBTable");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create and set up the content pane.
    SimpleDBTable newContentPane = new SimpleDBTable();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }

    http://forum.java.sun.com/thread.jspa?threadID=626207

  • JTable print issue

    If I print from Excel, I get a fixed number of columns irrespective of the size of the window. But when I print a JTable, what I see on paper is dependent on the table size. If I run the following code, I can print all 7 columns in the table on 1 page. But if I maximize the window and then print, the table prints over multiple pages printing 2 columns per page. This is pretty bad out-of-the-box behavior for JTable. How can I make it behave like Excel?
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.PrinterException;
    import javax.swing.*;
    public class TablePrintDemo extends JFrame
         public static void main(String[] args)
              new TablePrintDemo();
         public TablePrintDemo()
              Object[][] rowData = new Object[][] {
                        { "1", "2", "3", "4", "5", "6", "7" },
                        { "2", "3", "4", "5", "6", "7", "8" },
                        { "3", "4", "5", "6", "7", "8", "9" },
                        { "4", "5", "6", "7", "8", "9", "10" },
                        { "5", "6", "7", "8", "9", "10", "11" },
                        { "6", "7", "8", "9", "10", "11", "12" },
                        { "7", "8", "9", "10", "11", "12", "13" },
                        { "8", "9", "10", "11", "12", "13", "14" },
                        { "9", "10", "11", "12", "13", "14", "15" },
                        { "10", "11", "12", "13", "14", "15", "16" } };
              final JTable table = new JTable(rowData, new Object[]
                { "A", "B", "C", "D", "E", "F", "G" });
              table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
              JScrollPane scroll = new JScrollPane(table);
              this.setLayout(new BorderLayout());
              this.add(scroll, BorderLayout.CENTER);
              JButton printButton = new JButton("Print");
              JPanel buttonPanel = new JPanel();
              buttonPanel.setLayout(new FlowLayout());
              buttonPanel.add(printButton);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.add(buttonPanel, BorderLayout.SOUTH);
              this.pack();
              this.setVisible(true);
              printButton.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent evt)
                        try {
                             table.print(JTable.PrintMode.NORMAL);
                        } catch (PrinterException e) {
                             e.printStackTrace();
    }

    Hello Dear... Use the print method with FIX_WIDTH. This will compress the table/scale the table to fit the page width.
    table.print(JTable.PrintMode.FIT_WIDTH);I hope this will solve your problem...
    Good Luck!!

  • JTable Print problem

    Hello guys, i am here to take help of yours. I want to take the preview of the Jtable before printing of the JTable take place but i dont want to use any reporting tool for that. I want an frame in which i can get the preview of the table data just like the report. but as it will be incorporated into my code it will take much less time. So please help me in writing that code.
    If you have any printing class that can provide the Preview of JTable than it would be a great help.
    Thanks for any help that you provide.

    I tried but it does not change anything despite the documentation :
    NORMAL
    public static final JTable.PrintMode NORMAL
    Printing mode that prints the table at its current size, spreading both columns and rows across multiple pages if necessary.
    FIT_WIDTH
    public static final JTable.PrintMode FIT_WIDTH
    Printing mode that scales the output smaller, if necessary, to fit the table's entire width (and thereby all columns) on each page; Rows are spread across multiple pages as necessary.
    I 'd like also to print without all cells separation and lines (like print in a blank page only the data and not separations of the jtable) thank you

  • Jtable.print()

    hey all,
    ok... i have a little problem trying to print a jtable. the printing itself is no big deal and it works fine. however the column headers are printed blurry and pixelated. i know that this has to do something with the look and feel because when i use the java laf then the column names are printed perfectly fine. so as soon as i use another laf the headers are blurry. the laf im using is:
    de.javasoft.plaf.synthetica.SyntheticaBlackStarLookAndFeelim using java 5 and i did a little research and i found out that this is probably a bug, does anyone know a workaround? i already tried to use a printerjob but didn't make a difference. so im kinda stuck :(

    Are you using your own implementation of Printable? If you have jdk 1.5, you can simply call myTable.print () and swing does the rest

  • IPhoto crops again when printing

    I crop a photo, then hit Done.
    But then, when I hit Print I photo (appears to) then crop it again.
    Why?
    Thanks

    Most likely your photos are in a different aspect ratio than your prints - for example most digital photos are in a 4 x 3 ratio or 1.3333333 to 1 (my camera's maximum is 3072 x 2304 - 1.333333 to 1)
    If the print size is different than that then something has to give - so for a 6 x 4 print (1.5 to 1) either something has to be cropped, white space added or pixels squashed in one direction creating distortion - iPhoto crops
    If you do NOT want autocropping then simply crop your photos to the correct ratios BEFORE printing or print at the same ratio as the original photo (probably 1.333333 to 1) size - if you are going to print 4 x 6 they you crop to 4 x 6
    LN

  • Again Wireless Printing problem

    I am just upgrading to a new iMac alu 24", new all in one printer canon MP970 and aebs. I receive my printer and aebs about 14 days before my new iMac. I installed all on my "old" iMac G4 800Mhz working with Tiger. All was working fine exept the USB airdisk (Very slow).
    Now with my nieuw iMac with Leopard: Aebs work fine with internet and other computer connected on my network, airdisk is still to slow.
    I spend many hours to try install my printer on different way. I am still not abble to print wireless. Amazing, i can scan, use the memory cards reader and the printer utility. The most vexing as Mac User is that it work flawless with Vista.
    The consol error log give alway the same
    E [15/Jan/2008:14:45:07 +0100] CUPS-Add-Modify-Printer: Unauthorized
    I [15/Jan/2008:14:45:07 +0100] Saving printers.conf...
    I [15/Jan/2008:14:45:07 +0100] Printer "CanonMP970_seriesNetwork" modified by "yl".
    I [15/Jan/2008:14:45:55 +0100] [Job 57] Adding start banner page "none".
    I [15/Jan/2008:14:45:55 +0100] [Job 57] Adding job file of type application/postscript.
    I [15/Jan/2008:14:45:55 +0100] [Job 57] Adding end banner page "none".
    I [15/Jan/2008:14:45:55 +0100] [Job 57] Queued on "CanonMP970_seriesNetwork" by "yl".
    I [15/Jan/2008:14:45:55 +0100] [Job 57] Started filter /usr/libexec/cups/filter/pstops (PID 328)
    I [15/Jan/2008:14:45:55 +0100] [Job 57] Started backend /usr/libexec/cups/backend/lpd (PID 329)
    W [15/Jan/2008:14:45:55 +0100] [Job 57] réparable : l’hôte du réseau '10.0.1.198' est occupé ; nouvel essai dans 5
    Other is that when i update to 10.5.1, it was also an update to Remote Desktop Client 3.2.1
    After each installation of update i repair the unix permissions. I receive the message: ATTENTION : the file SUID « System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/MacOS/ARDA gent » is modified and shoud not be repaired.
    Any ideas is welcome. Quioury.

    Hello, back after a few days. Support Canon sent me a reply. But I found another solution before my trip and everything works fine.
    Here's what I did, it might help other Canon network printers user.
    Checked the version of the software, noticed that the printer driver was newer than mine, downloaded and installed (my network printer only refuse to print ). Still no printing.Than I just started again but from scratch:
    Reinstall the upgrade with my MP970 only connected to my computer via the USB cable, start "Canon ij Network" redo a configuration as during the initial installation. When at the end of installation after connecting cable "Lan" and unplugged the USB cable. In the dialogue box (Printer List) I click add another printer. A dialogue box opens told me that the printer is already set and if I desire to reconfigure: I click yes and the installation ends. In conclusion for "upgrades" we nead to repeat the configuration from the start. Quioury.

  • Jtable printing color

    When i try to print my Jtable, everything that is gray prints as a purplish color. How do i get rid of that? One of these things is a checkbox in the cell adn the other is the table header.

    No ideas??
    Please, help!

  • JTable printing code produces blank last page on Windows LAF, OK on Metal

    I've been banging my head on this one for hours. I'm printing JTables, handling the pagination myself (built in Printable is far too limited). I've one table which can have a variable number of columns, with some column counts it's fine, with others the last page simply comes up blank. Because the scale adjusts it may have something to do with the number of rows on the last page. 5 or 6 it screws up, 20 or so it's fine.
    This is the code that prints the section:
        public void print(Graphics2D graphics, Rectangle2D area, int pageIndex, String pageLabel) throws PrinterException {
            Shape oldClip = graphics.getClip();
            AffineTransform oldXForm = graphics.getTransform();
    //        graphics.clip(area);
            double y = area.getY();
            graphics.translate(area.getX(), area.getY());
            if(resize) {
                double stretch = area.getWidth() / (double)table.getColumnModel().getTotalColumnWidth();
                graphics.scale(stretch, stretch);
            if(table.getTableHeader() != null) {
                table.getTableHeader().print(graphics);
                graphics.translate(0, table.getTableHeader().getHeight());
            Rectangle tableBlock = new Rectangle(table.getX(), table.getY(), table.getColumnModel().getTotalColumnWidth(), 0);
            int rowNo;
            int frp = firstRowOnPage.get(pageIndex);
            int frnp = pageIndex + 1 >= firstRowOnPage.size() ? table.getRowCount() :
                firstRowOnPage.get(pageIndex + 1);
            for(rowNo = 0; rowNo < frp; rowNo++)
                tableBlock.y += table.getRowHeight(rowNo);
            for(;rowNo < frnp; rowNo++)
                tableBlock.height += table.getRowHeight(rowNo);
            graphics.translate(0, -tableBlock.y);
            graphics.setPaint(Color.BLACK);
            graphics.draw(tableBlock);
            graphics.clip(tableBlock);
            table.print(graphics);
            graphics.setTransform(oldXForm);
            graphics.setClip(oldClip);
        }Bascially it selects the block of rows to print by setting a clip box on the whole table size, and translates to bring the block to the top of the page.
    The rectangle drawn to the clip box is fine. table.print simply doesn't paint anything.
    I'm starting to think this might be a bug in the Windows LAF TableUI, because I've just tried switching to Metal and it works fine. Anyone had similar problems?

    Similar problems, just not with printing a JTable. Your problem might be totaly different but I have found that components change size (dimensions) and sub component sizes (like table columns) when you view them on different look and feels.

  • JTable: printing  more lines

    I am reusing the code from http://manning.com/sbe/files/uts2/Chapter22html/Chapter22.htm to print a JTable. Is there anyone has any idea how to change the code in order to make the margin narrower for printing more? It is because it prints another page after printing 17 lines.
    public int print(Graphics pg, PageFormat pageFormat, int pageIndex) throws PrinterException{
       if (pageIndex >= m_maxNumPage)
          return NO_SUCH_PAGE;
       pg.translate((int)pageFormat.getImageableX(), (int)pageFormat.getImageableY());
       int wPage = 0;
       int hPage = 0;
       pageFormat.setOrientation(PageFormat.LANDSCAPE);
       if (pageFormat.getOrientation() == pageFormat.PORTRAIT){
          wPage = (int)pageFormat.getImageableWidth();
          hPage = (int)pageFormat.getImageableHeight();
       else{
          wPage = (int)pageFormat.getImageableWidth();
          wPage += wPage/2;
          hPage = (int)pageFormat.getImageableHeight();
          pg.setClip(0, 0, wPage, hPage);
       int y = 0;
       pg.setColor(Color.black);
       Font fn = pg.getFont();
       FontMetrics fm = pg.getFontMetrics();
       y += fm.getAscent();
       y += 20;
       Font headerFont = m_table.getFont().deriveFont(Font.BOLD);
       pg.setFont(headerFont);
       fm = pg.getFontMetrics();
       TableColumnModel colModel = m_table.getColumnModel();
       int nColumns = colModel.getColumnCount();
       int x[] = new int[nColumns];
       x[0] = 0;
       int h = fm.getAscent();
       y += h;
       int nRow, nCol;
       for (nCol = 0; nCol < nColumns; nCol++){
          TableColumn tk = colModel.getColumn(nCol);
          int width = tk.getWidth();
          if (x[nCol] + width > wPage){
         nColumns = nCol;
         break;
          if (nCol + 1 < nColumns)
         x[nCol + 1] = x[nCol] + width;
          String title = (String)tk.getIdentifier();
          pg.drawString(title, x[nCol], y);
       pg.setFont(m_table.getFont());
       fm = pg.getFontMetrics();
       int header = y;
       h  = fm.getHeight();
       int rowH = Math.max((int)(h * 1.5), 10);
       int rowPerPage = (hPage - header)/rowH;
       m_maxNumPage = Math.max((int)Math.ceil(m_table.getRowCount()/(double)rowPerPage), 1);
       TableModel tblModel = m_table.getModel();
       int iniRow = pageIndex * rowPerPage;
       int endRow = Math.min(m_table.getRowCount(), iniRow + rowPerPage);
       for(nRow = iniRow; nRow < endRow; nRow++){
          y += h;
          for(nCol = 0; nCol < nColumns; nCol++){
         int col = m_table.getColumnModel().getColumn(nCol).getModelIndex();
         Object obj = m_table.getValueAt(nRow, col);
         String str = obj.toString();
         pg.setColor(Color.black);
         pg.drawString(str, x[nCol], y);
       System.gc();
       return PAGE_EXISTS;
    }

    i have posted there. moving to Burundi from Canada, where i purchased the computer, is not conducive to calling apple ($$$$$$$$$/bad phone lines) or a conveniently located Apple repair shop (or even internet or electrical grid, for that matter).
    What i hope is that enough internet ire may coax more publicity and perhaps a proper response for a defective manufacturing issue. then, with a viable repair/replacement/warranty extension program, and an actual published/documented solution to the published/documented fault, i can confidently spend the enormous effort/investment to have my computer actually FIXED.
    plus it feels good to vent.

  • Urgent need of your help for multiple JTables Print from a single JPanel

    I need your help to print multiple table content from JPanel
    JTables are generated dynamically in a JPanel or JPanels. I need to take print as it is in JPanel

    Alternatively you could write a simple class to print JTables with a series of calls to paintString( myString), and various calls to fillRect(...) tfor asthetics. It is quite simple. I currently use such a class that I wrote in under 200 lines of code that has a very professional look, and the print jobs are less than half the size of printing the JTable directly.
    The idea being that it takes a JTable as a parameter ( and maybe other params to control color, style, font, etc... ). It would have one primary method, print() which actually handles the printing, It may also uses other methods to control the look of the application.
    A problem I have faced with printing a JTable directly is ensuring that the botom row on each page and the top row on every page after the first one lines up correctly. After a while it was simply easier, and more customizable, to write my own print class.
    AC

  • Me again! - printing count results

    hello,
    i made a post earlier about this and someone replied but i still couldn't get it to work. i have to create a game (paper scissors rock) and it has to keep count of the number of wins player 1 and 2 have. i have to use separate methods. the problem is for some reason when it prints the number of wins it comes up with 0. i have cut out any unneeded code. please please help:
    public class question2a
    public static void main(String[] args)
    char quit = 'y';
    char c1 = 0;
    char c2 = 0;
    int player1wins = 0;
    int player2wins = 0;
    do
    question2a.getinput();
    question2a.winnercalculation(c1, c2, player1wins, player2wins);
    System.out.println("Do you want to play again [y/n]");
    quit = SavitchIn.readChar();
    SavitchIn.read();
    } while (quit != 'n');
    question2a.outputresults(player1wins, player2wins);
    public static void getinput()
    char c1;
    char c2;
    int player1wins = 0;
    int player2wins = 0;
    System.out.println("Player 1 please enter a letter");
    c1 = SavitchIn.readChar();
    SavitchIn.read();
    System.out.println("Player 2 please enter a letter");
    c2 = SavitchIn.readChar();
    SavitchIn.read();
    private static void winnercalculation(char c1, char c2, int player1wins, int player2wins)
    char rock = 'r';
    char paper = 'p';
    char scissors = 's';
    if ((c1 == rock) && (c2 == scissors)) //rock and scissors
    System.out.println("Player 1 Wins!");
    player1wins = player1wins + 1;
    else if ((c1 == rock) && (c2 == paper)) //rock and paper
    System.out.println("Player 2 Wins!");
    player2wins = player2wins + 1;
    else if ((c1 == scissors) && (c2 == rock)) //scissors and rock
    System.out.println("Player 2 Wins!");
    player2wins = player2wins + 1;
    public static void outputresults (int player1wins, int player2wins)
    System.out.println("Player 1 has had "+player1wins+" number of wins");
    System.out.println("Player 2 has had "+player2wins+" number of wins");
    if you need the code for the savitchIn tell me and i will post it

    Local variables are defined inside of methods. Fields are defined outside of methods. (Well there's more to it than that but that's how you can tell them apart.)
    But actually I misread your code. You defined c1 and c2 as local variables in main().
    So your code is fundamentally flawed.
    The easiest thing is to make these fields, static as mambo2 said:
    public class question2a
      static char c1 = 0;
      static char c2 = 0;
      static int player1wins = 0;
      static int player2wins = 0;
      public static void main(String[] args)
    // etcOr, better yet, you could rework your code to actually be a real OOP program.
    Either way, read the manual and learn about field/variable scoping, static vs instance fields, etc.

  • JTable print problem width

    Hello,
    I found the print() method for the JTable object to print my reports.
    Here looks fine but when I print it , I have only 50% of my outcoming page that is displayed.
    And so, The columns are compacted and I can't real correctly the data and it is not usable.
    Why?
    thanks

    I tried but it does not change anything despite the documentation :
    NORMAL
    public static final JTable.PrintMode NORMAL
    Printing mode that prints the table at its current size, spreading both columns and rows across multiple pages if necessary.
    FIT_WIDTH
    public static final JTable.PrintMode FIT_WIDTH
    Printing mode that scales the output smaller, if necessary, to fit the table's entire width (and thereby all columns) on each page; Rows are spread across multiple pages as necessary.
    I 'd like also to print without all cells separation and lines (like print in a blank page only the data and not separations of the jtable) thank you

Maybe you are looking for