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

Print this page




  45 import javax.swing.plaf.*;
  46 import javax.swing.table.*;
  47 import javax.swing.border.*;
  48 
  49 import java.text.NumberFormat;
  50 import java.text.DateFormat;
  51 import java.text.MessageFormat;
  52 
  53 import javax.print.attribute.*;
  54 import javax.print.PrintService;
  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 import sun.swing.SwingLazyValue;
  61 
  62 /**
  63  * The <code>JTable</code> is used to display and edit regular two-dimensional tables
  64  * of cells.
  65  * See <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html">How to Use Tables</a>
  66  * in <em>The Java Tutorial</em>
  67  * for task-oriented documentation and examples of using <code>JTable</code>.
  68  *
  69  * <p>
  70  * The <code>JTable</code> has many
  71  * facilities that make it possible to customize its rendering and editing
  72  * but provides defaults for these features so that simple tables can be
  73  * set up easily.  For example, to set up a table with 10 rows and 10
  74  * columns of numbers:
  75  * <p>
  76  * <pre>
  77  *      TableModel dataModel = new AbstractTableModel() {
  78  *          public int getColumnCount() { return 10; }
  79  *          public int getRowCount() { return 10;}
  80  *          public Object getValueAt(int row, int col) { return new Integer(row*col); }
  81  *      };
  82  *      JTable table = new JTable(dataModel);
  83  *      JScrollPane scrollpane = new JScrollPane(table);
  84  * </pre>
  85  * <p>


2472 
2473     /**
2474      * Returns the foreground color for selected cells.
2475      *
2476      * @return the <code>Color</code> object for the foreground property
2477      * @see #setSelectionForeground
2478      * @see #setSelectionBackground
2479      */
2480     public Color getSelectionForeground() {
2481         return selectionForeground;
2482     }
2483 
2484     /**
2485      * Sets the foreground color for selected cells.  Cell renderers
2486      * can use this color to render text and graphics for selected
2487      * cells.
2488      * <p>
2489      * The default value of this property is defined by the look
2490      * and feel implementation.
2491      * <p>
2492      * This is a <a href="http://java.sun.com/docs/books/tutorial/javabeans/properties/bound.html">JavaBeans</a> bound property.
2493      *
2494      * @param selectionForeground  the <code>Color</code> to use in the foreground
2495      *                             for selected list items
2496      * @see #getSelectionForeground
2497      * @see #setSelectionBackground
2498      * @see #setForeground
2499      * @see #setBackground
2500      * @see #setFont
2501      * @beaninfo
2502      *       bound: true
2503      * description: A default foreground color for selected cells.
2504      */
2505     public void setSelectionForeground(Color selectionForeground) {
2506         Color old = this.selectionForeground;
2507         this.selectionForeground = selectionForeground;
2508         firePropertyChange("selectionForeground", old, selectionForeground);
2509         repaint();
2510     }
2511 
2512     /**
2513      * Returns the background color for selected cells.
2514      *
2515      * @return the <code>Color</code> used for the background of selected list items
2516      * @see #setSelectionBackground
2517      * @see #setSelectionForeground
2518      */
2519     public Color getSelectionBackground() {
2520         return selectionBackground;
2521     }
2522 
2523     /**
2524      * Sets the background color for selected cells.  Cell renderers
2525      * can use this color to the fill selected cells.
2526      * <p>
2527      * The default value of this property is defined by the look
2528      * and feel implementation.
2529      * <p>
2530      * This is a <a href="http://java.sun.com/docs/books/tutorial/javabeans/properties/bound.html">JavaBeans</a> bound property.
2531      *
2532      * @param selectionBackground  the <code>Color</code> to use for the background
2533      *                             of selected cells
2534      * @see #getSelectionBackground
2535      * @see #setSelectionForeground
2536      * @see #setForeground
2537      * @see #setBackground
2538      * @see #setFont
2539      * @beaninfo
2540      *       bound: true
2541      * description: A default background color for selected cells.
2542      */
2543     public void setSelectionBackground(Color selectionBackground) {
2544         Color old = this.selectionBackground;
2545         this.selectionBackground = selectionBackground;
2546         firePropertyChange("selectionBackground", old, selectionBackground);
2547         repaint();
2548     }
2549 
2550     /**




  45 import javax.swing.plaf.*;
  46 import javax.swing.table.*;
  47 import javax.swing.border.*;
  48 
  49 import java.text.NumberFormat;
  50 import java.text.DateFormat;
  51 import java.text.MessageFormat;
  52 
  53 import javax.print.attribute.*;
  54 import javax.print.PrintService;
  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 import sun.swing.SwingLazyValue;
  61 
  62 /**
  63  * The <code>JTable</code> is used to display and edit regular two-dimensional tables
  64  * of cells.
  65  * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/table.html">How to Use Tables</a>
  66  * in <em>The Java Tutorial</em>
  67  * for task-oriented documentation and examples of using <code>JTable</code>.
  68  *
  69  * <p>
  70  * The <code>JTable</code> has many
  71  * facilities that make it possible to customize its rendering and editing
  72  * but provides defaults for these features so that simple tables can be
  73  * set up easily.  For example, to set up a table with 10 rows and 10
  74  * columns of numbers:
  75  * <p>
  76  * <pre>
  77  *      TableModel dataModel = new AbstractTableModel() {
  78  *          public int getColumnCount() { return 10; }
  79  *          public int getRowCount() { return 10;}
  80  *          public Object getValueAt(int row, int col) { return new Integer(row*col); }
  81  *      };
  82  *      JTable table = new JTable(dataModel);
  83  *      JScrollPane scrollpane = new JScrollPane(table);
  84  * </pre>
  85  * <p>


2472 
2473     /**
2474      * Returns the foreground color for selected cells.
2475      *
2476      * @return the <code>Color</code> object for the foreground property
2477      * @see #setSelectionForeground
2478      * @see #setSelectionBackground
2479      */
2480     public Color getSelectionForeground() {
2481         return selectionForeground;
2482     }
2483 
2484     /**
2485      * Sets the foreground color for selected cells.  Cell renderers
2486      * can use this color to render text and graphics for selected
2487      * cells.
2488      * <p>
2489      * The default value of this property is defined by the look
2490      * and feel implementation.
2491      * <p>
2492      * This is a <a href="http://docs.oracle.com/javase/tutorial/javabeans/writing/properties.html">JavaBeans</a> bound property.
2493      *
2494      * @param selectionForeground  the <code>Color</code> to use in the foreground
2495      *                             for selected list items
2496      * @see #getSelectionForeground
2497      * @see #setSelectionBackground
2498      * @see #setForeground
2499      * @see #setBackground
2500      * @see #setFont
2501      * @beaninfo
2502      *       bound: true
2503      * description: A default foreground color for selected cells.
2504      */
2505     public void setSelectionForeground(Color selectionForeground) {
2506         Color old = this.selectionForeground;
2507         this.selectionForeground = selectionForeground;
2508         firePropertyChange("selectionForeground", old, selectionForeground);
2509         repaint();
2510     }
2511 
2512     /**
2513      * Returns the background color for selected cells.
2514      *
2515      * @return the <code>Color</code> used for the background of selected list items
2516      * @see #setSelectionBackground
2517      * @see #setSelectionForeground
2518      */
2519     public Color getSelectionBackground() {
2520         return selectionBackground;
2521     }
2522 
2523     /**
2524      * Sets the background color for selected cells.  Cell renderers
2525      * can use this color to the fill selected cells.
2526      * <p>
2527      * The default value of this property is defined by the look
2528      * and feel implementation.
2529      * <p>
2530      * This is a <a href="http://docs.oracle.com/javase/tutorial/javabeans/writing/properties.html">JavaBeans</a> bound property.
2531      *
2532      * @param selectionBackground  the <code>Color</code> to use for the background
2533      *                             of selected cells
2534      * @see #getSelectionBackground
2535      * @see #setSelectionForeground
2536      * @see #setForeground
2537      * @see #setBackground
2538      * @see #setFont
2539      * @beaninfo
2540      *       bound: true
2541      * description: A default background color for selected cells.
2542      */
2543     public void setSelectionBackground(Color selectionBackground) {
2544         Color old = this.selectionBackground;
2545         this.selectionBackground = selectionBackground;
2546         firePropertyChange("selectionBackground", old, selectionBackground);
2547         repaint();
2548     }
2549 
2550     /**