34 35 import java.beans.*; 36 37 import java.io.ObjectOutputStream; 38 import java.io.ObjectInputStream; 39 import java.io.IOException; 40 41 import javax.accessibility.*; 42 43 import javax.swing.event.*; 44 import javax.swing.plaf.*; 45 import javax.swing.table.*; 46 import javax.swing.border.*; 47 48 import java.text.NumberFormat; 49 import java.text.DateFormat; 50 import java.text.MessageFormat; 51 52 import javax.print.attribute.*; 53 import javax.print.PrintService; 54 import sun.reflect.misc.ReflectUtil; 55 56 import sun.swing.SwingUtilities2; 57 import sun.swing.SwingUtilities2.Section; 58 import static sun.swing.SwingUtilities2.Section.*; 59 import sun.swing.PrintingStatus; 60 61 /** 62 * The <code>JTable</code> is used to display and edit regular two-dimensional tables 63 * of cells. 64 * See <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/table.html">How to Use Tables</a> 65 * in <em>The Java Tutorial</em> 66 * for task-oriented documentation and examples of using <code>JTable</code>. 67 * 68 * <p> 69 * The <code>JTable</code> has many 70 * facilities that make it possible to customize its rendering and editing 71 * but provides defaults for these features so that simple tables can be 72 * set up easily. For example, to set up a table with 10 rows and 10 73 * columns of numbers: 3387 int hitRowIndex = rowAtPoint(p); 3388 3389 if ((hitColumnIndex != -1) && (hitRowIndex != -1)) { 3390 TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex); 3391 Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex); 3392 3393 // Now have to see if the component is a JComponent before 3394 // getting the tip 3395 if (component instanceof JComponent) { 3396 // Convert the event to the renderer's coordinate system 3397 Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false); 3398 p.translate(-cellRect.x, -cellRect.y); 3399 MouseEvent newEvent = new MouseEvent(component, event.getID(), 3400 event.getWhen(), event.getModifiers(), 3401 p.x, p.y, 3402 event.getXOnScreen(), 3403 event.getYOnScreen(), 3404 event.getClickCount(), 3405 event.isPopupTrigger(), 3406 MouseEvent.NOBUTTON); 3407 3408 tip = ((JComponent)component).getToolTipText(newEvent); 3409 } 3410 } 3411 3412 // No tip from the renderer get our own tip 3413 if (tip == null) 3414 tip = getToolTipText(); 3415 3416 return tip; 3417 } 3418 3419 // 3420 // Editing Support 3421 // 3422 3423 /** 3424 * Sets whether editors in this JTable get the keyboard focus 3425 * when an editor is activated as a result of the JTable 3426 * forwarding keyboard events for a cell. | 34 35 import java.beans.*; 36 37 import java.io.ObjectOutputStream; 38 import java.io.ObjectInputStream; 39 import java.io.IOException; 40 41 import javax.accessibility.*; 42 43 import javax.swing.event.*; 44 import javax.swing.plaf.*; 45 import javax.swing.table.*; 46 import javax.swing.border.*; 47 48 import java.text.NumberFormat; 49 import java.text.DateFormat; 50 import java.text.MessageFormat; 51 52 import javax.print.attribute.*; 53 import javax.print.PrintService; 54 55 import sun.awt.AWTAccessor; 56 import sun.awt.AWTAccessor.MouseEventAccessor; 57 import sun.reflect.misc.ReflectUtil; 58 59 import sun.swing.SwingUtilities2; 60 import sun.swing.SwingUtilities2.Section; 61 import static sun.swing.SwingUtilities2.Section.*; 62 import sun.swing.PrintingStatus; 63 64 /** 65 * The <code>JTable</code> is used to display and edit regular two-dimensional tables 66 * of cells. 67 * See <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/table.html">How to Use Tables</a> 68 * in <em>The Java Tutorial</em> 69 * for task-oriented documentation and examples of using <code>JTable</code>. 70 * 71 * <p> 72 * The <code>JTable</code> has many 73 * facilities that make it possible to customize its rendering and editing 74 * but provides defaults for these features so that simple tables can be 75 * set up easily. For example, to set up a table with 10 rows and 10 76 * columns of numbers: 3390 int hitRowIndex = rowAtPoint(p); 3391 3392 if ((hitColumnIndex != -1) && (hitRowIndex != -1)) { 3393 TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex); 3394 Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex); 3395 3396 // Now have to see if the component is a JComponent before 3397 // getting the tip 3398 if (component instanceof JComponent) { 3399 // Convert the event to the renderer's coordinate system 3400 Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false); 3401 p.translate(-cellRect.x, -cellRect.y); 3402 MouseEvent newEvent = new MouseEvent(component, event.getID(), 3403 event.getWhen(), event.getModifiers(), 3404 p.x, p.y, 3405 event.getXOnScreen(), 3406 event.getYOnScreen(), 3407 event.getClickCount(), 3408 event.isPopupTrigger(), 3409 MouseEvent.NOBUTTON); 3410 MouseEventAccessor meAccessor = AWTAccessor.getMouseEventAccessor(); 3411 meAccessor.setCausedByTouchEvent(newEvent, 3412 meAccessor.isCausedByTouchEvent(event)); 3413 3414 tip = ((JComponent)component).getToolTipText(newEvent); 3415 } 3416 } 3417 3418 // No tip from the renderer get our own tip 3419 if (tip == null) 3420 tip = getToolTipText(); 3421 3422 return tip; 3423 } 3424 3425 // 3426 // Editing Support 3427 // 3428 3429 /** 3430 * Sets whether editors in this JTable get the keyboard focus 3431 * when an editor is activated as a result of the JTable 3432 * forwarding keyboard events for a cell. |