Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-3355

SideBarFactory painting offset with large files

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Reopened
    • Major
    • Resolution: Unresolved
    • 8.2, 11.0
    • None
    • None
    • None

    Description

      When painting in the sidebar using the SideBarFactory, the painted Graphic is offset for large files. To reproduce, create a NetBeans plugin project and add the following class:

      package com.mycompany.sidebar_test;
      
      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.Graphics;
      import javax.swing.JComponent;
      import javax.swing.text.JTextComponent;
      import org.netbeans.spi.editor.SideBarFactory;
      
      public class MySidebarFactory implements SideBarFactory {
          @Override
          public JComponent createSideBar(JTextComponent jtc) {
              return new MySidebar();
          }
      
          private class MySidebar extends JComponent {
              @Override
              protected void paintComponent(Graphics g) {
                  g.setColor(Color.BLUE);
                  g.fillRect(0, 0, 10, 1000); // Paint blue rectangle starting at the top of the sidebar with height of 1000px 
              }
      
              @Override
              public Dimension getPreferredSize() {
                  Dimension dimension = new Dimension(this.getParent().getSize());
                  dimension.width = 10;
      
                  return dimension;
              }
          }
      }
      

      Register the SideBarFactory using the following layers.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
      <filesystem>
          <folder name="Editors">
              <folder name="SideBar">
                  <file name="com-mycompany-sidebar_test-MySidebarFactory.instance">
                      <attr name="location" stringvalue="West"/>
                  </file>
              </folder>
          </folder>
      </filesystem>
      

      Now start the plugin and open a project containing a large file for example the StrBuilder.java from the apache commons lib.

      The painting is offset by a large amount as you can see in the attached screenshot (blue rectangle should start in line 1, not 2150). When shortening the file and re-opening it, the marker moves, so I suppose this is related to the file size.

      Attachments

        1. Bildschirmfoto von 2019-11-07 19-34-21.png
          114 kB
          Benedikt Schlagberger
        2. Bildschirmfoto von 2021-03-01 10-41-15.png
          108 kB
          Benedikt Schlagberger
        3. Bildschirmfoto von 2021-03-01 11-28-24.png
          93 kB
          Benedikt Schlagberger
        4. Bildschirmfoto von 2021-03-01 11-30-57.png
          179 kB
          Benedikt Schlagberger
        5. sidebar_test.zip
          5 kB
          Benedikt Schlagberger

        Activity

          People

            Unassigned Unassigned
            bschlagberger Benedikt Schlagberger
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: