Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.0
    • Fix Version/s: 0.9.4
    • Component/s: Table
    • Labels:
      None
    • Environment:

      Operating System: Windows XP
      Platform: PC

    • Issuezilla Id:
      897

      Description

      Using Nimbus the default renderer for Boolean.class, JRendererCheckBox, does
      not paint properly in a JXTable. This only happens in Nimbus. I have posted a
      self-contained small example below. A workaround is to adapt the JRendererLabel
      to work with checkboxes; this works OK.

      import java.util.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.border.*;
      import javax.swing.table.*;
      import javax.swing.event.*;
      import org.jdesktop.swingx.*;
      import org.jdesktop.swingx.renderer.*;
      import org.jdesktop.swingx.border.*;
      import org.jdesktop.swingx.painter.*;
      import org.jdesktop.swingx.decorator.*;
      import org.jdesktop.swingx.table.ColumnHeaderRenderer;

      class TableDemoNimbusCheckBox{

      static JXTable getTable(){
      JXTable jt = new JXTable (new DemoTableModel());
      jt.setHighlighters(HighlighterFactory.createSimpleStriping
      (HighlighterFactory.LINE_PRINTER),
      new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, Color.CYAN,
      Color.BLUE ));
      //use ButtonProvider, should be CheckBoxProvider
      jt.setDefaultRenderer(JCheckBox.class, new DefaultTableRenderer
      (new ButtonProvider(){
      protected JCheckBox createRendererComponent()

      { return new JRendererLabelCheckBox(); }


      }));
      return jt;
      }

      public static void main (String [] args){
      try

      { // UIManager.setLookAndFeel ("com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); UIManager.setLookAndFeel ("org.jdesktop.swingx.plaf.nimbus.NimbusLookAndFeel"); // UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName()); }

      catch (Exception e)

      { System.out.println(e); }

      JFrame frame = new JFrame();
      frame.getContentPane().add(new JScrollPane
      (TableDemoNimbusCheckBox.getTable()));
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(800, 200);
      frame.setVisible(true);
      ;
      }
      }

      class DemoTableModel extends AbstractTableModel {
      String[] columnNames =

      { "First Name", "Last Name", "Default CheckBox Renderer", "LabelRenderer CheckBox"}

      ;

      Object[][] data = {

      {"Mary", "Campione",new Boolean(false),new Boolean(false)}

      ,

      {"Alison", "Huml", new Boolean(false),new Boolean(false)}

      ,

      {"Kathy", "Walrath", new Boolean(true ),new Boolean(true) }

      ,

      {"Sharon", "Zakhour", new Boolean(false),new Boolean(false)}

      ,

      {"Philip", "Milne", new Boolean(true ),new Boolean(true) }

      };

      public String getColumnName(int col)

      { return columnNames[col]; }

      public int getColumnCount()

      { return 4; }

      public int getRowCount()

      { return 5; }

      public boolean isCellEditable( int row, int col)

      { return false; }

      public Class< ?> getColumnClass( int columnIndex ) {
      switch ( columnIndex ) {

      case ( 0 ):
      case ( 1 ):

      { return String.class; }

      case ( 2 ):

      { return Boolean.class; }


      case ( 3 ):

      { return JCheckBox.class; }


      }
      return Object.class;
      }

      public Object getValueAt( int rowIndex, int columnIndex )

      { return data[ rowIndex ][ columnIndex ]; }

      public void setValueAt( Object value, int rowIndex, int columnIndex )

      { if (columnIndex==0) data[ rowIndex ][ columnIndex ]=(String) value; if (columnIndex==1) data[ rowIndex ][ columnIndex ]=(String) value; if (columnIndex==2) data[ rowIndex ][ columnIndex ]=(Boolean) value; if (columnIndex==3) data[ rowIndex ][ columnIndex ]=(Boolean) value; }

      }

      /*

      • MODIFIED FOR CHECKBOX
      • ... extends JCheckBox
      • $Id: JRendererLabel.java,v 1.11 2008/03/03 11:46:40 kleopatra Exp $
        */
        class JRendererLabelCheckBox extends JCheckBox implements PainterAware {
        protected Painter painter;
        public JRendererLabelCheckBox() { super(); setOpaque(true); }

        public boolean isOpaque()

        Unknown macro: { Color back = getBackground(); Component p = getParent(); if (p != null) { p = p.getParent(); } boolean colorMatch = (back != null) && (p != null) && back.equals(p.getBackground()) && p.isOpaque(); return !colorMatch && super.isOpaque(); }

        public void setPainter(Painter painter)

        { this.painter = painter; }

        public Painter getPainter()

        { return painter; }

        protected void paintComponent(Graphics g) {
        if (painter != null)

        Unknown macro: { if (isOpaque()) { paintComponentWithPainter((Graphics2D) g); } else { paintPainter(g); super.paintComponent(g); } }

        else

        { super.paintComponent(g); }

        }
        private void paintPainter(Graphics g)

        Unknown macro: { Graphics2D scratch = (Graphics2D) g.create(); try { painter.paint(scratch, this, getWidth(), getHeight()); } finally { scratch.dispose(); } }

        protected void paintComponentWithPainter(Graphics2D g) {
        if (ui != null)

        Unknown macro: { Graphics2D scratchGraphics = (Graphics2D) g.create(); try { scratchGraphics.setColor(getBackground()); scratchGraphics.fillRect(0, 0, getWidth(), getHeight()); paintPainter(g); ui.paint(scratchGraphics, this); } finally { scratchGraphics.dispose(); } }


        }
        public void setToolTipText(String text)

        { putClientProperty(TOOL_TIP_TEXT_KEY, text); }

        public void invalidate() {}
        public void validate() {}
        public void revalidate() {}
        public void repaint(long tm, int x, int y, int width, int height) {}
        public void repaint(Rectangle r) { }
        public void repaint() { }
        protected void firePropertyChange(String propertyName, Object oldValue,
        Object newValue)

        Unknown macro: { if ("text".equals(propertyName)) { super.firePropertyChange(propertyName, oldValue, newValue); } }

        public void firePropertyChange(String propertyName, boolean oldValue,
        boolean newValue) { }
        }

        Activity

        Hide
        kleopatra added a comment -

        problem was not only with Nimbus: in other LAFs the background was lost if used
        combined with painters.

        started: overridden isOpaque - looks okay now. Not entirely sure about the
        contentAreaFilled property, there was a reason for doing things differently from
        a JRendererLabel (which I forgot, need to dig in my notes). The initial
        intention was to switch over to the "normal" painter-aware components once the
        painter support agreed on one. Which petered out ...

        in the same sweep: overriden the usual suspect for "performance reasons" (not to
        be believed, but for consistency <g>)

        Please check if the change solves your problem (since build #1097)

        Thanks
        Jeanette

        Show
        kleopatra added a comment - problem was not only with Nimbus: in other LAFs the background was lost if used combined with painters. started: overridden isOpaque - looks okay now. Not entirely sure about the contentAreaFilled property, there was a reason for doing things differently from a JRendererLabel (which I forgot, need to dig in my notes). The initial intention was to switch over to the "normal" painter-aware components once the painter support agreed on one. Which petered out ... in the same sweep: overriden the usual suspect for "performance reasons" (not to be believed, but for consistency <g>) Please check if the change solves your problem (since build #1097) Thanks Jeanette
        Hide
        kleopatra added a comment -


        taking no complaints as a good sign, so closing

        Show
        kleopatra added a comment - taking no complaints as a good sign, so closing

          People

          • Assignee:
            kleopatra
            Reporter:
            jimbo8
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: