< prev index next >

src/java.desktop/share/classes/javax/swing/JTable.java

Print this page




  39 import java.io.ObjectOutputStream;
  40 import java.io.ObjectInputStream;
  41 import java.io.IOException;
  42 import java.io.InvalidObjectException;
  43 
  44 import javax.accessibility.*;
  45 
  46 import javax.swing.event.*;
  47 import javax.swing.plaf.*;
  48 import javax.swing.table.*;
  49 import javax.swing.border.*;
  50 
  51 import java.text.NumberFormat;
  52 import java.text.DateFormat;
  53 import java.text.MessageFormat;
  54 import java.util.List;
  55 
  56 import javax.print.attribute.*;
  57 import javax.print.PrintService;
  58 
  59 import sun.misc.ManagedLocalsThread;
  60 import sun.reflect.misc.ReflectUtil;
  61 
  62 import sun.swing.SwingUtilities2;
  63 import sun.swing.SwingUtilities2.Section;
  64 import static sun.swing.SwingUtilities2.Section.*;
  65 import sun.swing.PrintingStatus;
  66 
  67 /**
  68  * The <code>JTable</code> is used to display and edit regular two-dimensional tables
  69  * of cells.
  70  * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/table.html">How to Use Tables</a>
  71  * in <em>The Java Tutorial</em>
  72  * for task-oriented documentation and examples of using <code>JTable</code>.
  73  *
  74  * <p>
  75  * The <code>JTable</code> has many
  76  * facilities that make it possible to customize its rendering and editing
  77  * but provides defaults for these features so that simple tables can be
  78  * set up easily.  For example, to set up a table with 10 rows and 10
  79  * columns of numbers:


6358         final PrintRequestAttributeSet copyAttr = attr;
6359 
6360         // this runnable will be used to do the printing
6361         // (and save any throwables) on another thread
6362         Runnable runnable = () -> {
6363             try {
6364                 // do the printing
6365                 job.print(copyAttr);
6366             } catch (Throwable t) {
6367                 // save any Throwable to be rethrown
6368                 synchronized(lock) {
6369                     printError = t;
6370                 }
6371             } finally {
6372                 // we're finished - hide the dialog
6373                 printingStatus.dispose();
6374             }
6375         };
6376 
6377         // start printing on another thread
6378         Thread th = new ManagedLocalsThread(runnable);
6379         th.start();
6380 
6381         printingStatus.showModal(true);
6382 
6383         // look for any error that the printing may have generated
6384         Throwable pe;
6385         synchronized(lock) {
6386             pe = printError;
6387             printError = null;
6388         }
6389 
6390         // check the type of error and handle it
6391         if (pe != null) {
6392             // a subclass of PrinterException meaning the job was aborted,
6393             // in this case, by the user
6394             if (pe instanceof PrinterAbortException) {
6395                 return false;
6396             } else if (pe instanceof PrinterException) {
6397                 throw (PrinterException)pe;
6398             } else if (pe instanceof RuntimeException) {




  39 import java.io.ObjectOutputStream;
  40 import java.io.ObjectInputStream;
  41 import java.io.IOException;
  42 import java.io.InvalidObjectException;
  43 
  44 import javax.accessibility.*;
  45 
  46 import javax.swing.event.*;
  47 import javax.swing.plaf.*;
  48 import javax.swing.table.*;
  49 import javax.swing.border.*;
  50 
  51 import java.text.NumberFormat;
  52 import java.text.DateFormat;
  53 import java.text.MessageFormat;
  54 import java.util.List;
  55 
  56 import javax.print.attribute.*;
  57 import javax.print.PrintService;
  58 

  59 import sun.reflect.misc.ReflectUtil;
  60 
  61 import sun.swing.SwingUtilities2;
  62 import sun.swing.SwingUtilities2.Section;
  63 import static sun.swing.SwingUtilities2.Section.*;
  64 import sun.swing.PrintingStatus;
  65 
  66 /**
  67  * The <code>JTable</code> is used to display and edit regular two-dimensional tables
  68  * of cells.
  69  * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/table.html">How to Use Tables</a>
  70  * in <em>The Java Tutorial</em>
  71  * for task-oriented documentation and examples of using <code>JTable</code>.
  72  *
  73  * <p>
  74  * The <code>JTable</code> has many
  75  * facilities that make it possible to customize its rendering and editing
  76  * but provides defaults for these features so that simple tables can be
  77  * set up easily.  For example, to set up a table with 10 rows and 10
  78  * columns of numbers:


6357         final PrintRequestAttributeSet copyAttr = attr;
6358 
6359         // this runnable will be used to do the printing
6360         // (and save any throwables) on another thread
6361         Runnable runnable = () -> {
6362             try {
6363                 // do the printing
6364                 job.print(copyAttr);
6365             } catch (Throwable t) {
6366                 // save any Throwable to be rethrown
6367                 synchronized(lock) {
6368                     printError = t;
6369                 }
6370             } finally {
6371                 // we're finished - hide the dialog
6372                 printingStatus.dispose();
6373             }
6374         };
6375 
6376         // start printing on another thread
6377         Thread th = new Thread(null, runnable, "JTablePrint", 0, false);
6378         th.start();
6379 
6380         printingStatus.showModal(true);
6381 
6382         // look for any error that the printing may have generated
6383         Throwable pe;
6384         synchronized(lock) {
6385             pe = printError;
6386             printError = null;
6387         }
6388 
6389         // check the type of error and handle it
6390         if (pe != null) {
6391             // a subclass of PrinterException meaning the job was aborted,
6392             // in this case, by the user
6393             if (pe instanceof PrinterAbortException) {
6394                 return false;
6395             } else if (pe instanceof PrinterException) {
6396                 throw (PrinterException)pe;
6397             } else if (pe instanceof RuntimeException) {


< prev index next >