< 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.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:


3403         if ((hitColumnIndex != -1) && (hitRowIndex != -1)) {
3404             TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex);
3405             Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex);
3406 
3407             // Now have to see if the component is a JComponent before
3408             // getting the tip
3409             if (component instanceof JComponent) {
3410                 // Convert the event to the renderer's coordinate system
3411                 Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false);
3412                 p.translate(-cellRect.x, -cellRect.y);
3413                 @SuppressWarnings("deprecation")
3414                 final int modifiers = event.getModifiers();
3415                 MouseEvent newEvent = new MouseEvent(component, event.getID(),
3416                                           event.getWhen(), modifiers,
3417                                           p.x, p.y,
3418                                           event.getXOnScreen(),
3419                                           event.getYOnScreen(),
3420                                           event.getClickCount(),
3421                                           event.isPopupTrigger(),
3422                                           MouseEvent.NOBUTTON);



3423 
3424                 tip = ((JComponent)component).getToolTipText(newEvent);
3425             }
3426         }
3427 
3428         // No tip from the renderer get our own tip
3429         if (tip == null)
3430             tip = getToolTipText();
3431 
3432         return tip;
3433     }
3434 
3435 //
3436 // Editing Support
3437 //
3438 
3439     /**
3440      * Sets whether editors in this JTable get the keyboard focus
3441      * when an editor is activated as a result of the JTable
3442      * forwarding keyboard events for a cell.




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


3405         if ((hitColumnIndex != -1) && (hitRowIndex != -1)) {
3406             TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex);
3407             Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex);
3408 
3409             // Now have to see if the component is a JComponent before
3410             // getting the tip
3411             if (component instanceof JComponent) {
3412                 // Convert the event to the renderer's coordinate system
3413                 Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false);
3414                 p.translate(-cellRect.x, -cellRect.y);
3415                 @SuppressWarnings("deprecation")
3416                 final int modifiers = event.getModifiers();
3417                 MouseEvent newEvent = new MouseEvent(component, event.getID(),
3418                                           event.getWhen(), modifiers,
3419                                           p.x, p.y,
3420                                           event.getXOnScreen(),
3421                                           event.getYOnScreen(),
3422                                           event.getClickCount(),
3423                                           event.isPopupTrigger(),
3424                                           MouseEvent.NOBUTTON);
3425                 MouseEventAccessor meAccessor = AWTAccessor.getMouseEventAccessor();
3426                 meAccessor.setCausedByTouchEvent(newEvent,
3427                     meAccessor.isCausedByTouchEvent(event));
3428 
3429                 tip = ((JComponent)component).getToolTipText(newEvent);
3430             }
3431         }
3432 
3433         // No tip from the renderer get our own tip
3434         if (tip == null)
3435             tip = getToolTipText();
3436 
3437         return tip;
3438     }
3439 
3440 //
3441 // Editing Support
3442 //
3443 
3444     /**
3445      * Sets whether editors in this JTable get the keyboard focus
3446      * when an editor is activated as a result of the JTable
3447      * forwarding keyboard events for a cell.


< prev index next >