Announcement Announcement Module
Collapse
No announcement yet.
Scrolling on a JTable Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scrolling on a JTable

    Hi,
    I am displaying a jtable built on BeanTableModel in a scrollpane. When I slide the horizontal scrollbar to my right, I loose data on my screen and I get a nullpointer exception. I have copied the stacktrace below.. any idea why this is happening.

    Tennyson

    java.lang.NullPointerException
    at javax.swing.JTable.prepareRenderer(Unknown Source)
    at javax.swing.plaf.basic.BasicTableUI.paintCell(Unkn own Source)
    at javax.swing.plaf.basic.BasicTableUI.paintCells(Unk nown Source)
    at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
    at javax.swing.plaf.ComponentUI.update(Unknown Source)
    at javax.swing.JComponent.paintComponent(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JViewport.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent._paintImmediately(Unknown Source)
    at javax.swing.JComponent.paintImmediately(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unkno wn Source)
    at javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  • #2
    code

    we need more details:

    did you override any mthods on your jtable...
    apply any custom renderers...

    I have seen this when I overode the repareRenderer() method.
    Last edited by mlavwilson2; Mar 20th, 2006, 09:43 AM.

    Comment


    • #3
      Hi

      NO and NO.
      I am not overrideing any methods or have a custom cell render. When I scroll to my right at some point the column headers are not aligned right on top of the corresponding data grid. That's when I get these null pointer exceptions.

      Comment


      • #4
        get us your code

        Paste in your code to construct the table.
        The bean being displayed.
        Any modified ComponentFactory code.

        Comment


        • #5
          // code that constructs the table

          BeanTableModel tableModel = new WorkManagementTableModel(messageSource);
          tableModel.setRows(dashboardWorkMgmtDAO.loadAll()) ;

          // create the JTable instance
          table = TableUtils.createStandardSortableTable(tableModel) ;

          TableUtils.installDefaultRenderers(table);

          table.addMouseListener(new MouseAdapter(){
          public void mouseClicked(MouseEvent e)
          {
          if (e.getClickCount() == 2)
          {
          Point p = e.getPoint();
          int row = table.rowAtPoint(p);
          FileNumber = getFileNumber(row);
          propertiesExecutor.execute();
          }
          }

          private Long getFileNumber(int row) {
          TableModel model = table.getModel();
          Long number = (Long) model.getValueAt(row, 15);
          return number;
          }
          } );


          JScrollPane scrollPane = new JScrollPane(table);
          scrollPane.getViewport().setOpaque(true);
          scrollPane.getViewport().setBackground(table.getBa ckground());
          return scrollPane;
          }


          // Bean being displayed

          @SuppressWarnings( { "serial", "unchecked" })
          public class WorkManagementTableModel extends BeanTableModel {

          public WorkManagementTableModel(MessageSource messageSource) {
          super(DashboardWorkMgmt.class, messageSource);
          }

          @Override
          protected String[] createColumnPropertyNames() {
          return new String[] { "createdBy", "transactionStatusCd", "icon",
          "transactionTypeCd", "logonId", "processingPortCd", "custName",
          "commInvNo", "brokerFiler", "entryNo", "userClassId",
          "brokerTeam", "companyNo", "divisionNo", "fileNo" };
          }

          @Override
          protected Class[] createColumnClasses() {
          return new Class[] { String.class, String.class, String.class,
          String.class, String.class, String.class, String.class,
          String.class, String.class, Integer.class, String.class,
          String.class, short.class, short.class, long.class };
          }

          }


          // don't have any modified component factory..

          Thanks for your quick reply. I really appreciate it

          Comment


          • #6
            I would not use spring table support.

            I am not sure why richclient has thier own table sorting... I would take a look at glazedlist, that project is a must for any swing development.

            Do you still get errors after removing: TableUtils.installDefaultRenderers(table);?

            Comment


            • #7
              Hi

              Sorry about the delayed response.. I got this one working.. the problem is here

              @Override
              protected Class[] createColumnClasses() {
              return new Class[] { String.class, String.class, String.class,
              String.class, String.class, String.class, String.class,
              String.class, String.class, Integer.class, String.class,
              String.class, short.class, short.class, long.class };
              }

              I change all the primitive types short and long to Wrapper types Short and Long. It works fine.

              Thanks again. I appericiate your responses. I totally agree with GlazedList. I started with glazed list and in some weblog, I read beantablemodel and glazedListModel unified?? I am not so sure about that now.
              Thanks a lot

              Have a good day

              Tennyson

              Comment

              Working...
              X