Package javax.swing.table

Examples of javax.swing.table.DefaultTableCellRenderer


        method.setAccessible(true);
        return method.invoke(currentObject, (Object [])null);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        DefaultTableCellRenderer renderer = (DefaultTableCellRenderer)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

        // Add whitespace to left and right of columns
        renderer.setBorder(new EmptyBorder(insets.top, insets.left + (iconSupported ? 0 : 8), insets.bottom, insets.right + 8));

        // Set the correct colours.  CraigM 27/11/2007
        // TF:05/05/2009:Corrected these dependent upon the hasRowHighlights property of a ListViewTable
        boolean ignoreSelection = (table instanceof ListViewTable) && (!((ListViewTable)table).getHasRowHighlights());
        if (isSelected && !ignoreSelection) {
            if (table.hasFocus()) {
                renderer.setBackground(table.getSelectionBackground());
                renderer.setForeground(table.getSelectionForeground());
            }
            else {
                renderer.setBackground(java.awt.Color.lightGray);
                renderer.setForeground(java.awt.Color.black);
            }
        }
        else {
            renderer.setBackground(table.getBackground());
            renderer.setForeground(table.getForeground());
        }

        // Display icon if defined for this column
        if(value instanceof DisplayNode) {
            try {
                // Get the real value via reflection. This will either be the text of
                // the object or an image data. The first case (text) will be when this
                // is column 0 in the array and we need to use the icon image with the
                // retrieved text, and the second case will be when there is an explicitly
                // mapped image associated with this column.
                //Object objValue = AlignedCellRenderer.expressionExecute(value, this.methodName, "().");
                Object objValue = AlignedCellRenderer.expressionExecute(value, this.methodName, ".");

                int iconHeight = 0;
                if (objValue != null && objValue instanceof ImageData) {
                    // This is a column defined as an image, it can contain no text
                    ImageData id = (ImageData)objValue;
                    renderer.setIcon(id.asScaledIconImage(ICON_WIDTH, ICON_HEIGHT));
                    iconHeight = ICON_HEIGHT;
                }
                else {
                    // display icon
                    // TF:24/7/07: In Forte, if there was no selected icon, the small icon would display, even if selected.
                    Icon icon = null;
                    ImageData image = ((DisplayNode)value).getDVSmallIcon();
                    // COLET 20/01/2009 : Check if the selected image is valid by checking isNull(). If its empty, use the small icon. This is what Forte did.
                    ImageData selectedImage = ((DisplayNode)value).getDVSelectedIcon();
                    if (isSelected && selectedImage != null && !selectedImage.isNull()) {
                        image = selectedImage;
                    }

                    // We have an icon
                    if(image != null) {
                        icon = image.asScaledIconImage(ICON_WIDTH, ICON_HEIGHT);
                        iconHeight = ICON_HEIGHT;
                    }

                    // We don't have an icon and we are the left column, however, some other row does, so pad the space with an invisible image.
                    else if (column == 0 && this.hasIconInColumn1(table)) {
                        icon = invisibleIcon;
                    }
                   
                    //COLET 20/01/2009 : Add some shading to the icon. Forte would have the icon painted like this.
                    //                   By default, Java wont paint the background colour over the icon. Lets mimic Forte.
                    if(icon != null && isSelected) {
                      icon = new AlphaBlendedIcon(icon, getBackground(), BLENDED_ICON_TRANSPARENCY);
                    }
                   
                    renderer.setIcon(icon);

                    if(objValue != null) {
                        renderer.setText(objValue.toString());

                        // If we don't have an icon and we are the left most column, pad the space.
                        if (icon == null && column == 0) {
                            renderer.setText(" " + renderer.getText());
                        }

                        // The column sorts by comparing DVNodeText on the display node,
                        // so this should be set using the displayed text
//                        DisplayNode node = (DisplayNode)value;
//                        TextData td = node.getDVNodeText();
//                        if(td == null || td.toString() == null || td.toString().length() == 0
//                            || !objValue.toString().equals(td.toString())) {
//                            node.setDVNodeText(objValue.toString());
//                        }
                    }
                }

                // set row height sufficient for icon
                int currentHeight = table.getRowHeight();
                int newHeight = Math.max(iconHeight, currentHeight);
                if(newHeight != currentHeight) {
                    table.setRowHeight(newHeight);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        else {
            renderer.setIcon(null);
        }

        // Don't have a completely blank cell, as this will cause the row highlighting to not work.  CraigM 14/09/2007.
        if (renderer.getIcon() == null && renderer.getText().length() == 0) {
            renderer.setText(" ");
        }
        return renderer;
    }
View Full Code Here


     * TagId=21
     * isInherited=FALSE
     */
    public DefaultTableCellRenderer getqq_thingsArray_pg() {
        if (qq_thingsArray_pg == null) {
            qq_thingsArray_pg = new DefaultTableCellRenderer();
            qq_thingsArray_pg.setIcon(new ImageIcon(Main.class.getResource("main.qq_thingsArray_pg.png")));
            qq_thingsArray_pg.setName("pg");
            qq_thingsArray_pg.setOpaque( true );
            ArrayFieldCellHelper.setUpCellEditor(qq_thingsArray_pg, qq_things, 2, false);
            qq_thingsArray_pg.setSize(new Dimension(31, 12));
View Full Code Here

        }
        return qq_thingsArray_pg;
    }

    public void setqq_thingsArray_pg(DefaultTableCellRenderer value) {
        DefaultTableCellRenderer oldValue = qq_thingsArray_pg;
        qq_thingsArray_pg = value;
        this.qq_Listeners.firePropertyChange("qq_thingsArray_pg", oldValue, value);
    }
View Full Code Here

            }
        });

        sorttmodel = new SortTModel(jtableResulset,jtmodel);

        DefaultTableCellRenderer df = new DefaultTableCellRenderer.UIResource(){
            public void setValue(Object value) {
                String cadena = "";
                try {
                    if (value != null && value instanceof byte[])
                    {
View Full Code Here

     * @param row
     * @param column
     * @return
     */
    public boolean isCellBlank(int row, int column){
        DefaultTableCellRenderer cr = (DefaultTableCellRenderer)table.getCellRenderer(row, column);
        return cr.getBackground().equals(cr.getForeground());
    }
View Full Code Here

     * @param row
     * @param column
     * @param blank
     */
    public void setCellBlank(int row, int column, boolean blank){
        DefaultTableCellRenderer cr = (DefaultTableCellRenderer)table.getCellRenderer(row, column);
        if (blank){
            cr.setBackground(SystemColor.control);
            cr.setForeground(SystemColor.control);
        } else {
            cr.setBackground(null);
            cr.setForeground(null);
        }
    }
View Full Code Here

        this.name = name;
        setEditor(cellEditor);
        setRenderer(cellRenderer);

        if (cellRenderer instanceof DefaultTableCellRenderer){
            DefaultTableCellRenderer dtce = (DefaultTableCellRenderer)cellRenderer;
            this.setAlignment(UIutils.javaAlignementToForte(dtce.getHorizontalAlignment()));
        }
    }
View Full Code Here

    }

    public int getAlignment() {
        int result;
        if (this.renderer instanceof DefaultTableCellRenderer) {
            DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) this.renderer;
            result = dtcr.getHorizontalAlignment();
        } else {
            result = SwingConstants.LEFT;
        }
        return UIutils.javaAlignementToForte(result);
    }
View Full Code Here

        return UIutils.javaAlignementToForte(result);
    }

    public void setAlignment(int pAlignment) {
        if (this.renderer instanceof DefaultTableCellRenderer) {
            DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) this.renderer;
            dtcr.setHorizontalAlignment(UIutils
                    .forteAlignmentToJava(pAlignment));
        }
    }
View Full Code Here

     * @param row
     * @param column
     * @return
     */
    public boolean isCellBlank(int row, int column){
        DefaultTableCellRenderer cr = (DefaultTableCellRenderer)table.getCellRenderer(row, column);
        return cr.getBackground().equals(cr.getForeground());
    }
View Full Code Here

TOP

Related Classes of javax.swing.table.DefaultTableCellRenderer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.